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

Declarations and Initializations Questions and Answers

Answer: B

Correct answer: External, Internal and None

Three linkages exist. External linkage makes a name visible across translation units, internal linkage confines it to one file - which is what static at file scope gives - and no linkage belongs to block-scope names, each declaration of which denotes a distinct object.

Please log in or register to report this question.

12.

Which of the following special symbol allowed in a variable name?

Answer: D

Correct answer: _ (underscore)

An identifier may contain letters, digits and the underscore, and may not begin with a digit. The underscore is therefore the only special character permitted, and it is how multi-word names are written where the language will not accept a hyphen or a space.

Please log in or register to report this question.

13.

How would you round off a value from 1.66 to 2.0?

Answer: A

Correct answer: ceil(1.66)

ceil returns the smallest integer not less than its argument, so 1.66 becomes 2.0. floor would give 1.0, and neither roundup nor roundto exists in the standard library - the standard rounding function is round.

Please log in or register to report this question.

14.

By default a real number is treated as a

Answer: B

Correct answer: double

An unsuffixed floating constant such as 3.14 has type double, and so does the result of ordinary floating arithmetic. A constant is made float by an f suffix and long double by an L. This is why passing a float to a variadic function promotes it to double.

Please log in or register to report this question.

15.

Is the following statement a declaration or definition?
extern int i;

Answer: A

Correct answer: Declaration

extern int i; announces that an object named i of type int exists somewhere, without reserving storage for it. A definition is what allocates the storage, and there must be exactly one of those in the program however many declarations refer to it.

Please log in or register to report this question.

16.

When we mention the prototype of a function?

Answer: B

Correct answer: Declaring

A prototype declares the function - its name, return type and parameter types - so the compiler can check calls and convert arguments correctly. The definition is the body, written once. Calling requires the declaration to be visible, which is why prototypes go in headers.

Please log in or register to report this question.

17.

Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

Answer: C

Correct answer: rem = fmod(3.14, 2.1);

The % operator requires integer operands, so it will not compile here. fmod is the floating point remainder function declared in math.h, and it is the only one of the four options that computes what the question asks for.

Please log in or register to report this question.

18.

Does this compile without error?

int main()
{
for (int k = 0; k < 10> return 0;
}

Answer: C

Compilers implementing C90 does not allow this but compilers implementing C99 allow it.
Output:
$ cc pgm4.c
pgm4.c: In function ‘main’:
pgm4.c:4: error: ‘for’ loop initial declarations are only allowed in C99 mode
pgm4.c:4: note: use option -std=c99 or -std=gnu99 to compile your code

Please log in or register to report this question.

19.

Does this compile without error?

int main()
{
int k;
{
int k;
for (k = 0; k < 10; k++);
}
}

Answer: A

Correct answer: Yes

The inner braces open a new block, and a declaration in an inner block may reuse a name from an outer one - the inner k simply shadows the outer for the extent of that block. It is legal, though the shadowing is a common source of confusion and most compilers will warn about it.

Please log in or register to report this question.

20.

Which of the following declaration is not supported by C?

Answer: A

Correct answer: String str;

C has no String type; a string is an array of char terminated by a null, or a pointer to one. The other two declarations are perfectly valid: char *str is a pointer to char, and 3e2 is simply 300 written in exponential form.

Please log in or register to report this question.

Loading…
Tags: Declarations and Initializations Questions and Answers || Declarations and Initializations MCQ Questions and Answers || Declarations and Initializations GK Questions and Answers || Declarations and Initializations GK MCQ Questions || Declarations and Initializations Multiple Choice Questions and Answers || Declarations and Initializations GK || GK on Declarations and Initializations || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming