Hello to everyone,
I was doing some questions on C but don't know the answers to them, so I just want to cross check them here. Here are the questions.
1.I'm completely doubtful regarding this one. In the function f() which returns pointer to char, s is allocated space and string "goodbye" is copied to it. But in main() how is the function getting called and how is the output to it is 'A'. Also if I change the printf toCode:char *f() { char *s=malloc(8); strcpy(s,"goodbye"); } main() { char *f(); printf("%c",*f()='A'); }
the output becomes the first letter of the string getting copied i.e in this case 'g'.Code:printf("%c",*f());
Can someone please explain this code to me?
2. What does int *x[](); means ?
I think it's an array of pointers to function returning int. Am I correct? Also is there a specific procedure to be followed for complicated declarations like this one and others too?
3.What is the output of the following ?
The output to this is 4 but is this not an undefined behaviour? I think it's notCode:int i; i=1; i=i+2*i++; printf("%d",i);
Thanks in advance for your responses.