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


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
main()
{
char *p = "hello world";
p[0] = 'H';
printf("%s", p);
}



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

Answer is B) Hello World.p[0] is just replacing the value on the first index.



Its output will vary on tc , Visual Studio
and on ISO C99
On TC it will give Hello world'
But on Visual Studio and C99 it will give segmentation fault

Because

char *p="hello";
char a[10]="raj";
here p is a pointer its addres can be changed means it can be made to point to somewhere else
But if its internal characters are tried to change then result is undetermined.....
But in a[10]="raj";
Here internal contents can be changed but a can't point to another location.........



 Posted by: rajeev kumar    

Contact rajeev kumar  Contact rajeev kumar

I thought the base address can't be modified, this is what i get for the above program :

blr-nsstg-view1% ./a.out
Segmentation Fault (core dumped)



 Posted by: saikiran    

Contact saikiran  Contact saikiran


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
main()
{
int i, j;
scanf("%d %d"+scanf("%d %d", &i, &j));
printf("%d %d", i, j);
}


View Answer
main()
{
int i, j, *p;
i = 25;
j = 100;
p = &i; // Address of i is assigned to pointer p
printf("%f", i/(*p) ); // i is divided by pointer p
}


View Answer
union u
{
union u
{
int i;
int j;
}a[10];
int b[10];
}u;
main()
{
printf("n%d", sizeof(u));
printf(" %d", sizeof(u.a));
// printf("%d", sizeof(u.a[4].i));
}


View Answer
union u
{
struct st
{
int i : 4;
int j : 4;
int k : 4;
int l;
}st;
int i;
}u;
main()
{
u.i = 100;
printf("%d, %d, %d",u.i, u.st.i, u.st.l);
}

View Answer
#define SQR(x) x * x
main()
{
printf("%d", 225/SQR(15));
}


View Answer
main()
{
int i = 0xff ;
printf("n%d", i<<2);
}


View Answer
main()
{
int i;
float *pf;
pf = (float *)&i;
*pf = 100.00;
printf("n %d", i);
}


View Answer
main(int argc, char *argv[])
{
(main && argc) ? main(argc-1, NULL) : return 0;
}


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



View Answer
What is use of macro arguments in c?
what is major difference between normal macro definition and macro arguments.

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/5988/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.84