CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
main()
{
printf("%d, %d", sizeof('c'), sizeof(100));
}



Category C Interview Questions
Rating (0.0) By 0 users
Added on 7/18/2006
Views 818
Rate it!
Answers:

The answer is 2,2 coz sizeof return the memory occupied and "c" uses 1 byte to store character 'c' and the other byte to store NULL to indicate the end of string. 100 being stored as an interger would take 2 bytes



I am not sure how far the explanation mentioned above is correct???

I think sizeof('c') is different from sizeof("c").The explanation given was for sizeof("c").

As per the question is concerned,sizeof('c')
is nothing but sizeof(ascii value of c) which is nothing but an interger(99) so sizeof('c')== sizeof(99) which results in 2 for 16 bit compilers and 4 for 32 bit compilers.

Hence the answer is 2,2



 Posted by: Syed Baseer Ahmed    

Contact Syed Baseer Ahmed  Contact Syed Baseer Ahmed

It completely depends upon the compiler. Some compilers allocate 1 byte of memo for char variable. While some other allocate 2 bytes. Similarly, memory allocation for integer varies from compiler to compiler.



 Posted by: Chirantan Rajhans    

Contact Chirantan Rajhans  Contact Chirantan Rajhans


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
void func1(int (*a)[10])
{
printf("Ok it works");
}
void func2(int a[][10])
{
printf("Will this work?");
}

main()
{
int a[10][10];
func1(a);
func2(a);
}


View Answer
main()
{
char *a = "Hello ";
char *b = "World";
clrscr();
printf("%s", strcpy(a,b));
}


View Answer
main()
{
char *a = "Hello ";
char *b = "World";
clrscr();
printf("%s", strcat(a,b));
}


View Answer
struct Foo
{
char *pName;
char *pAddress;
};
main()
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
obj->pName = malloc(100);
obj->pAddress = malloc(100);
strcpy(obj->pName,"Your Name");
strcpy(obj->pAddress, "Your Address");
free(obj);
printf("%s", obj->pName);
printf("%s", obj->pAddress);
}


View Answer
struct Foo
{
char *pName;
};
main()
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
strcpy(obj->pName,"Your Name");
printf("%s", obj->pName);
}


View Answer
const int perplexed = 2;
#define perplexed 3
main()
{
#ifdef perplexed
#undef perplexed
#define perplexed 4
#endif
printf("%d",perplexed);
}


View Answer
How will you print % character?

View Answer

main()
{
char * strA;
char * strB = I am OK;
memcpy( strA, strB, 6);
}





























View Answer
main()
{
char *p = "hello world";
p[0] = 'H';
printf("%s", p);
}


View Answer
main()
{
int i, j;
scanf("%d %d"+scanf("%d %d", &i, &j));
printf("%d %d", i, j);
}


View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/5997/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.66