Key… 1. 1) Legal 2) Legal 3) Legal 4) Legal but not advised 5) Illegal: Contains the illegal character # 6) Illegal: Is a C keyword 7) Illegal: First character is a digit 2. Answer: Compiler error: Too many initializers Explanation:The array a is of size 4 but the string constant requires 6 bytes to get stored. 3. Option 3
4. Option 2
5. Option 4
9. Option 3
10. Option 1 11. Option 3
6. Option 3
7. Option 2
12.Option 1
13. Option 1 14.Option 2
15. Option 2 16. 77 17. Option 1 18. rtcent rtcent lexthonity error
20.
8. Option 1
21. complier
22. Answer : 2 2 2 2 Explanation:The pointer to any type is of same size. 23. Answer: Yes Explanation:The typename aType is known at the point of declaring the structure, because it is already typedefined. 24. Answer: No Explanation:When the declaration, typedef struct a aType; is encountered body of struct a is not known. This is known as ‘incomplete types’. So creating a variable of incomplete type is not possible. Because the memory needed for that variable will be unknown. 25. Answer: Compiler Error: Undefined structure date Explanation: Only declaration of struct date is available inside the structure definition of ‘student’ but to have a variable of type struct date the definition of the structure is required. 26. Answer: 770 Explanation: The integer value 256 in binary notation is: 00000001 00000010. It is stored in memory (small-endian) as:00000010 00000001 Result of the expression *++ptr = 3 makes the memory representation as: 00000010 00000011. So the integer corresponding to it is 00000011 00000010 => 770. 27. Answer: 21 28. Answer: 10 Explanation:The size of integer array of 10 elements is 10 * sizeof(int). The macro expands to sizeof(arr)/sizeof(int) => 10 * sizeof(int) / sizeof(int) => 10. 29. Answer: 1 Explanation: Arrays cannot be passed to functions as arguments and only the pointers can be passed. So the argument is equivalent to int * array (this is one of the very few places where [] and * usage are equivalent). The return statement becomes, sizeof(int *)/ sizeof(int) that happens to be equal in this case. 30. Answer: sizeof(p) = 2, sizeof(*p) = 1, strlen(p) = 4 ;
sizeof(a) = 5, strlen(a) = 4
31.
1 1 1 1 2 4 2 4 3 7 3 7 4 2 4 2 5 5 5 5 6 8 6 8 7 3 7 3 8 6 8 6 9 9 9 9 32. to 53 will be discussed during class 54. Answer: 4 1 55. Answer: 1 10 56. Answer: 10 10 57. Answer: garbage value 58. abt accumulator 59. i = -1, -i = 1 60. Answer: 11
explanation for question 17. Let the address of “s” starts at 3000. “s” is an array of pointers. It will ve the address of “black”, “white”, “yellow”, “violet”. Let assume S= 6500 4500 5500 3500 3000
3001
3002
ptr= 3003
3002
8000 8001 both “ptr” and “s” are character pointers. So the address increases by 1.
3001 8002
Let the address of ptr be 8000. Now p=ptr. Ie. p=8000. *++p means post increment of p. after this line gets executes the value of p=8001
3003
3000 8003
printf("%s",*--*++p + 3); in this sentence ++p=8002 *(8002) = 3001 --(3001) = 3000; *(3000)=3500; 3500+3=3503 this points to “c” of the “black” therefore printf(“%s”,3503) will print from “c” till “\0”. Hence the o/p “ck”. Explanation to question no.18 S= 4500 3500 3000
3001
p=3000; printf("%s ",++*p); Printf (“%s” ,++(*(3000)); Printf (“%s”, ++(3500)); Printf( “%s”, 3501); This points to “r” of “Atrcent”; So starting from r , it prints till “\0”. So it prints “rtcent” printf("%s ",*p++); printf(“%s”,*(3501)); hence once again prints “rtcent”.. because the pointer is still pointing the “r” of "Artcent”. After this line gets executed, now the pointer “p” gets incremented by 1.(because its post increment). Now the pointer becomes p=3001; printf("%s ",++*p); printf(“%s” ,++(*3001)); printf(“%s”,++(4500)); printf(“%s”,4501); so it starts printing from “l” of “Flexthonity” till “\0”. Thus the output will be “lexthonity”