C Miscellaneous - Study Mode
[#66] Determine Output: void main()
{
char *p="hi friends", *p1
p1=p
while(*p!='x00') ++*p++
printf("%s", p1)
}
Correct Answer
(B) ij!gsjfoet
Explanation
Solution: ++*p++ will be parse in the given order : 1. *p that is value at the location currently pointed by p will be taken 2. ++*p the retrieved value will be incremented 3. when
is encountered the location will be incremented that is p++ will be executed.
[#67] Determine Output: #include<stdio.h>
#define a 10
void main()
{
#define a 50
printf("%d", a)
}
Correct Answer
(A) 50
Explanation
Solution: The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.
[#68] Determine Output: #define clrscr() 100
void main()
{
clrscr()
printf("%d", clrscr())
}
Correct Answer
(C) 100
Explanation
Solution: Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs. The input program to compiler looks like this : void main ()
{ 100
printf ( " %d ", 100 )
} Note: 100
is an executable statement but with no action. So it doesn't give any problem.
[#69] Determine Output: void main()
{
printf("%p", main)
}
Correct Answer
(C) Some address will be printed
Explanation
Solution: Function names are just addresses (just like array names are addresses). main () is also a function. So the address of function main will be printed. %p in printf () specifies that the argument is an address. They are printed as hexadecimal numbers.
[#70] Determine Output: void main()
{
char far *farther, *farthest
printf("%d..%d", sizeof(farther), sizeof(farthest))
}
Correct Answer
(A) 4..2
Explanation
Solution: The second pointer is of char type and is not a far pointer.