CQuiz
Caveat: The quiz is intended for fun and educational purpose. The one or the other question is more academic, i.e., it should make you think ;)

If two pointers
p
andq
of the same type point to the same address, thenp == q
must evaluate to true.For this question I do not have a short answer. Have a look at this post for a detailed discussion.

The following two function declarations can be used interchangeably, i.e., they mean exactly the same:
The short answer is that the former declares a function with an unknown number and types of arguments while the latter declares a function without any argument, i.e., it is a nullary function.
Have a look at this post for a detailed discussion.

The following function declaration in conjunction with the function definition is valid.
That is a valid function declaration and definition. The declaration only introduces the function name
foo
without defining the number and types of arguments.Have a look at this post for a detailed discussion.

The following function declaration in conjunction with the function definition is valid.
This is not a valid function declaration in conjunction with the definition. The short answer is that whenever a function is called where no prototype is available, then the default argument promotions are applied. For example, a
float
is promoted to adouble
. In this case, the function type is not compatible with the function type after the default argument promotions.Have a look at this post for a detailed discussion.

The bit representation of the null pointer must have all bits zero.
The null pointer constant is defined by the C standard. However, the representation of the null pointer at runtime is not. Actually, the representation of pointers in general is not defined by the C standard. For example, the Symbolics Lisp Machine does not make use of numerical pointers at all but of tuples of the form
(object, offset)
. The representation of the null pointer in the Symbolics Lisp Machine is then(Nil, 0)
. 
An object may be declared before its type and, therefore, also its size is known as for example:
This is allowed in certain circumstances. A similar argument holds for arrays with an incomplete type.

Let
NULL
be the null pointer, thenNULL == 0
evaluates to true. 
The expression
(void *)0
evaluates to the null pointer 
If the expression
e
evaluates to0
, then(void *)e
evaluates to the null pointer.Only the null pointer constant converted to pointer type is guaranteed to equal the null pointer.

If the expression
e
evaluates to the null pointer, thene+0
, too.Null pointer arithmetics is undefined behavior in C.

In the following code fragment the expression
x == y
may evaluate to false.Variable
x
is not initialized and therefore holds an indeterminate value. According to C11 expressions involving indeterminate values result in undefined behavior. Hence “anything” might happen which includes that the expression may evaluate to false. 
Let
T
be a (derived) object type. The first assignment is valid C code. Is the second assignment valid, too?For this question I do not have a short answer. Have a look at this post for a detailed discussion.

The expression
1 < sizeof(int)
evaluates to false.The short answer is as follows. Operator
sizeof
returns an unsigned integer of typesize_t
. According to the usual arithmetic conversions (C11 § 6.3.1.8) the operand which is signed and has a lower rank than the unsigned operand, is converted to an unsigned integer type of the same rank as the unsigned operand. Any signed integer which is equivalent to1
has all bits set. Such a sequence of bits interpreted as an unsigned integer equals the maximal unsigned integer of each corresponding integer rank. In other words(unsigned int)1
equalsUINT_MAX
. The same holds true for all other integersshort int
,long int
, andlong long int
. Thus, the left operand of the relational operator evaluates to the maximal unsigned integer representable by an unsigned integer whose rank is equivalent to the rank ofsize_t
. Since there exists no unsigned integer with a same rank which is strictly greater, the expression is always false. 
The following two statements are equivalent.
The first assignment initializes an array with automatic or static storage duration (depends on whether
x
is declared in file or function scope) which is modifiable. Whereas the second assignment initializes a pointer to an array with static storage duration which is not necessarily modifiable. Or in other words arrays are not pointers.Have a look at this post for a detailed discussion.

Let
int a[42];
be an array, then all three expressionsa
and&a
and&a[0]
can be used interchangeably, i.e., they mean exactly the same.All three expressions evaluate to a pointer to the first element of the array. However, each expression has a different type. Have a look at this post for a detailed discussion.

Assume that the variables
a
,b
, andc
are initialized before read.Are the values for the variables
x
andz
always the same, i.e., does the expressionx == z
always evaluate to true at the end of the code fragment?Short answer: The integer promotions require that the value of each variable is promoted to size
int
, then the addition and division is performed. The resulting value is truncated and stored in the corresponding variable of each assignment, respectively. Provided that the addition may overflow the values forx
andz
may not equal.Long answer: The modulo operation is not distributive over division. Lets illustrate the problem by an example. Assume
a=255;
,b=1;
, andc=2;
, then for the first assignment we have that the value stored inx
equals the expression((255 + 1) / 2) % 256
which equals(256 / 2) % 256
which equals128 % 256
which finally equals128
. For the second assignment we have that the value stored iny
equals the expression(255 + 1) % 256
which equals256 % 256
which finally equals0
. N.B. an overflow occurred which is defined behavior for unsigned integers. For the last assignment we then have that the value stored inz
equals the expression(0 / 2) % 256
which equals0 % 256
which finally equals0
. Thereforex == z
is not always the case since128 != 0
.Fun fact 1: The modulo operation is distributive over addition, i.e.,
(a + b) % x == [(a % x) + (b % x)] % x
for alla,b,x
. Thus, if we change the division by an addition, then the values for the variablesx
andz
are always the same.Fun fact 2: We could change the first assignment to
uint8_t x = ((uint8_t)(a + b)) / c;
. Then the values for the variablesx
andz
are always the same, too. 
The expression
sizeof(char) == sizeof('x')
evaluates to true.Character constants have type
int
(C11 § 6.4.4.4 paragraph 10). Thus onlysizeof(int) == sizeof('x')
is guaranteed to evaluate to true.N.B. In terms of the C11 standard a character constant is either an integer character constant or a wide character constant. The former is a sequence of one or more multibyte characters. Thus 'abc' is a valid integer character constant where the representation is implementation defined. If an integer character constant contains a single character, then its value equals the integer representation of an object of type
char
which represents the very same single character.
Score
You answered 0 out of 0 questions correctly!