Interview Questions
C |
main() { |
Ans:
Compiler error: Lvalue required in function main |
Array names are pointer constants. So it cannot be modified.. |
main() |
Ans:
Compiler error: Undefined label 'here' in function main. |
Labels have functions scope, in other words The scope of the labels is limited to functions . The label 'here' is available in function fun() Hence it is not visible in function main.. |
main() |
Ans:
H |
* is a dereference operator & is a reference operator. They can be applied any number of times provided it is meaningful. Here p points to the first character in the string "Hello". *p dereferences it and so its value is H. Again & references it to an address and * dereferences it to the value H.. |
main() |
Ans:
400..300 |
Printf takes the values of the first two assignments of the program. Any number of printf's may be given. All of them take only the first two values. If more number of assignments given in the program,then printf will take garbage values.. |
void main() |
Ans:
4..2 |
The second pointer is of char type and not a far pointer. |
Enum colors {BLACK,BLUE,GREEN} |
Ans:
0..1..2 |
Enum assigns numbers starting from 0, if not explicitly defined. |
main() { |
Ans:
No output/error |
The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function). |
main() |
Ans:
Some address will be printed. |
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.. |
#include #define a 10 main() |
Ans:
50 |
The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.. |
#define square(x) x*x main() |
Ans:
64 |
The macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64. |