C Fundamentals - Study Mode

[#251] short testarray[4][3] = { {1}, {2,3}, {4,5,6}}
printf("%d", sizeof(testarray))
Assuming a short is two bytes long, what will be printed by the above code?
Correct Answer

(D) 24

Explanation

Solution: The following table provides the details of standard integer types with their storage sizes and value ranges − Type Storage size Value range char 1 byte -128 to 127 or 0 to 255 unsigned char 1 byte 0 to 255 signed char 1 byte -128 to 127 int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295 short 2 bytes -32,768 to 32,767 unsigned short 2 bytes 0 to 65,535 long 4 bytes -2,147,483,648 to 2,147,483,647 unsigned long 4 bytes 0 to 4,294,967,295

[#252] What will be the output of the following C code? #include <stdio.h>
void main()
{
int x = 97
char y = x
printf("%c
", y)
}
Correct Answer

(A) a

Explanation

Solution: 1. Declaration: int x = 97
2. Conversion: char y = x
3. ASCII Value: The ASCII value of 97 corresponds to the character 'a' . 4. Print: printf("%c
", y)
prints the character 'a' .

[#253] Will the following C code compile without any error? #include <stdio.h>
int main()
{
for (int k = 0
k < 10
k++)
return 0
}
Correct Answer

(C) Depends on the C standard implemented by compilers

[#254] What will be the final values of a and c in the following C statement? (Initial values: a = 2, c = 1) c = (c) ? a = 0 : 2
Correct Answer

(A) a = 0, c = 0

Explanation

Solution: Initial values: a = 2, c = 1
The statement is: c = (c) ? a = 0 : 2
This is a ternary conditional expression . The condition is (c) , which means if c is non-zero , the expression before the colon is executed. Since c = 1 (non-zero), the true part is executed: a = 0 Then the value of the true expression ( a = 0 ) is assigned to c . So now: a becomes 0 c becomes 0 (since the result of a = 0 is 0) Final values: a = 0, c = 0

[#255] What will be the output of the following C code? #include <stdio.h>
int main()
{
unsigned int a = 10
a = ~a
printf("%d
", a)
}
Correct Answer

(C) -11