Bloomberg LP Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 0 vote

Char a[] = "abc"; Here is is stored on stack.
and sizeof a is 4.. It counts \0

char *a = "abc" --- a is stored on stack. But abc is a const string... Its stored in initialized data segment.

- Asha February 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

for a[]: sizeof(a) 4 size of array of 4 chars including '\0' is 4
for *a : sizeof(a) 4 size of pointer is 4

- gomchol February 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

void main()
{
char a[]="abcdef";
char *b="abcdef";
printf("%d",sizeof(a)); ------> 6+1=7
printf("%d",sizeof(b)); ------> sizeof(pointer) which is 4
printf("%d",sizeof(*b); -------> 1
}

- motu August 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess, the difference between (1) Char a[]=”abc” and (2) char *a=”abc” is that,

(1) is a constant with size of 3 chars.
(2) is variable with variable size.(3 chars in this case)


to answer second part of the question i will copy/paste from
http://www.lysator.liu.se/c/c-faq/c-2.html
<paste>
The array declaration "char a[6];" requests that space for six characters be set aside, to be known by the name "a." That is, there is a location named "a" at which six characters can sit. The pointer declaration "char *p;" on the other hand, requests a place which holds a pointer. The pointer is to be known by the name "p," and can point to any char (or contiguous array of chars) anywhere.
</paste>

- morpheus February 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It should be 4 due to \0 at the end of the string

- proboy February 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

"a" in "a[]" is a constant pointer to a char , it cant be dereferenced . where as "a" in "*a" is a normal pointer to char it can be dereferenced.
you can change content of a[] where all the char from literal are4 copied to a char array . but you can not change "abc" which is a literal constant.

- Hemant February 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Char a[] = "abc"; Here is is stored on stack.
and sizeof a is 4.. It counts \0

char *a = "abc" --- a is stored on stack. But abc is a const string... Its stored in initialized data segment.

- Asha February 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I agree with gomchal

- desi February 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

go to this page for a very elaborate & clear answer
http://home.netcom.com/~tjensen/ptr/ch6x.htm

- Nikhil Sriv February 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thats a very good material.. Thanks Nikhil Sriv!

- Gireesh April 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Dear friends remember sizeof() works only at compile time .Both are stored in stack .

- Arindam March 12, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

3 and 2

- Anonymous September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

plz dont post bullshit here... it kind of confuses people.
sizeof -> char[] a will return 4 (abc\0)
-> char *a will return sizeof pointer
-> sizeof(*a) will return 1

- @Anonymous above me March 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In char a[]="abc",space is allocated for three characters and terminated with a NULL character.In char *a="abc",a is a pointer to the string.Hence in this declaration, a can be made to point to a different string whereas in the first declaration,a cannot be assigned to another string directly.It can be done only through strcpy...

- TOPCODER April 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

en . wikipedia . org / wiki / Data_segment

- gaurav July 06, 2010 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More