0% found this document useful (0 votes)
55 views3 pages

C Questions: 1: Answer: 5794

The document contains 5 C code snippets with questions about the output. 1. The code prints the values 57 and 94, as x and y are incremented and assigned in a confusing order. 2. An extern variable i is declared but not defined, causing a linker error. 3. Attempting to modify a constant value with ++ results in a compiler error. 4. Using a double negative (- -2) correctly evaluates to a positive 2. 5. Applying logical NOT (!) before comparing i to 14 results in i being assigned 0.

Uploaded by

Rajesh Paul
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views3 pages

C Questions: 1: Answer: 5794

The document contains 5 C code snippets with questions about the output. 1. The code prints the values 57 and 94, as x and y are incremented and assigned in a confusing order. 2. An extern variable i is declared but not defined, causing a linker error. 3. Attempting to modify a constant value with ++ results in a compiler error. 4. Using a double negative (- -2) correctly evaluates to a positive 2. 5. Applying logical NOT (!) before comparing i to 14 results in i being assigned 0.

Uploaded by

Rajesh Paul
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

C questions: 1.

main()
{ int x=20,y=35; x=y++ + x++; y= ++y + ++x; printf(%d%d\n,x,y); }

Answer: 5794 2. main()


{ extern int i; i=20; printf("%d",i); } Answer: Linker Error : Undefined symbol '_i' Explanation: extern storage class in the following declaration, extern int i; specifies to the compiler that the memory for i is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name i is available in any other program with memory space allocated for it. Hence a linker error has occurred .

3.

void main() { int const * p=5; printf(%d,++(*p)); } Answer: Compiler error: Cannot modify a constant value.

Explanation: p is a pointer to a constant integer. But we tried to change the value of the constant integer.

4. main() { int c=- -2; printf(c=%d,c); } Answer: c=2; Explanation: Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus= plus. Note: However you cannot give like 2. Because operator can only be applied to variables as a decrement operator (eg., i). 2 is a constant and not a variable. 5. main() { int i=10; i=!i>14; printf(i=%d,i); } Answer: i=0 Explanation: In the expression !i>14 , NOT (!) operator has more precedence than > symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).

You might also like