Machine-translated by Google. Questions are authored in English.
Top

Expressions Questions and Answers

121.

What will be the output of the following program?

#include <stdio.h>

int main()
{
static unsigned int a = 23;
register unsigned char c = 'R';
auto long unsigned q = 345L;
static long signed p = 345L;
printf("a = %u c = %c", a ,c);
printf("\nq = %ld p = %ld", q, p);
return 0;
}

 

Answer: A

Correct answer: a=23 c=R q = 345 p = 345

Each variable prints its own value, and the storage classes affect only lifetime and placement, not the values: a is 23, and c printed with %c shows the character R. The two long variables both hold 345 and print with %ld as 345. The only real trap is the case of the letters in the options - the format string writes a lower-case a.

Please log in or register to report this question.

122.

What will be the output of the following program?

#include <stdio.h>

int main()
{
register int i = 2;
static char ch = 'A';
auto float j;
int k;
k = ++ch && i;
k = ++ch;
j = i-- + ++k * 2;
printf("%d %f", k, j);
return 0;
}

 

Answer: C

Correct answer: 68 138.000000

Follow the four statements, with ch starting at 'A' = 65.

  1. k = ++ch && i; - ch becomes 66; both operands are non-zero, so k is 1.
  2. k = ++ch; - ch becomes 67 and k takes that value.
  3. j = i-- + ++k * 2; - i-- contributes 2 (leaving i at 1); ++k makes k 68, and \(68 \times 2 = 136\); so \(j = 2 + 136 = 138\).

Printed with %d and %f: 68 138.000000.

Please log in or register to report this question.

123.

What will be the output of the following program?

#include <stdio.h>

Void f(static int*, extern int);
Static int b = 12;
Int main()
{
Static int a[5];
Register int I;
For(I = 0; I < 2> A[i++] = 2 * i++;
F(a, b);
For(I = 0; I < 2> Printf(“%d”, b++);
Return 0;
}
Void f (static int *x, extern int y)
{
Register int I;
For(I = 0; I < 2> *(++x +1) + = 2;
Y + = 2;
}

 

Answer: C

Correct answer: 0 12, though the listing this depends on has been destroyed

The program text in this record cannot be trusted. Every identifier has been capitalised - Void, Static, Int, For, Printf - which alone would stop it compiling, since C is case sensitive; the quotation marks in the printf call have become typographic quotes; and each of the three for loops has lost its body, ending at I < 2> where the loop condition, the increment and the statement should be. That last damage is characteristic: a stray < in stored HTML swallows everything up to the next >, and here it has taken the working part of every loop with it. One thing can still be said about the original. It declares void f(static int*, extern int);, and neither of those storage classes may be applied to a function parameter - C permits only register there - so the program the question was built on would not have compiled either. The keyed answer is “0 12”, which is consistent with a program whose array elements are never usefully assigned and whose file-scope b is unchanged by the call, since y += 2 inside f alters only the local copy of the argument. Beyond that the item cannot be worked until the original listing is restored.

Please log in or register to report this question.

124.

Where will the space be allocated for an automatic storage class variable?

Answer: C

Correct answer: In memory

An automatic variable lives on the stack, which is memory. The register class is the one that asks for a CPU register, and even that is only a request. A compiler may of course keep an automatic variable in a register as an optimisation, but the storage class itself specifies memory.

Please log in or register to report this question.

125.

What will be the output of the following code?

#include <stdio.h>

int main()
{
extern int a;
static char j = 'E';
printf("%c %d", ++j, ++a);
return 0;
}

 

Answer: B

Correct answer: F 1

++j takes the static char from 'E' to 'F', which %c prints as the letter. extern int a; declares a variable defined at file scope elsewhere; such an object has static storage duration and is therefore zero-initialised, so ++a gives 1. Output: F 1.

Please log in or register to report this question.

Answer: B

Correct answer: For loop counter

register is worth asking for where a variable is accessed very often, and a loop counter is the classic case - it is read and written on every iteration. It cannot be used where the variable’s address is needed, since a register has no address. In practice modern compilers allocate registers better than the hint does, so the keyword is now of historical interest.

Please log in or register to report this question.

127.

A function cannot be defined inside another function

Answer: A

Correct answer: True

C has no nested functions: every function is defined at file scope, and a function definition inside another is a syntax error. (GCC offers nested functions as a non-standard extension, but that is not C.) What can be nested is a block, and a block may declare its own variables.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Expressions Questions and Answers || Expressions MCQ Questions and Answers || Expressions GK Questions and Answers || Expressions GK MCQ Questions || Expressions Multiple Choice Questions and Answers || Expressions GK || GK on Expressions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming