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

Declarations and Initializations Questions and Answers

11.

Which of the following is not a pointer declaration?

Answer: D

Correct answer: char a;

An array name decays to a pointer to its first element in nearly every context, so the first two declarations yield something usable as a pointer, and char *str is one outright. A plain char holds a single character and has no pointer nature at all.

Please log in or register to report this question.

12.

Is it true that a global variable may have several declarations, but only one definition?

Answer: A

Correct answer: Yes

Every file using a global variable declares it, so a program may contain many declarations of one object. The storage is reserved once, by the single definition, and the linker resolves every declaration to it. More than one definition is an error at link time.

Please log in or register to report this question.

13.

The name of the variable used in one function cannot be used in another function?

Answer: B

Correct answer: False

Each function has its own scope, so the same identifier may be used in as many functions as one likes and each denotes a distinct object. That independence is the point of block scope, and it is what allows a loop counter called i to appear throughout a program without conflict.

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.

Answer: C

Correct answer: A variable must be declared and defined at the same time

The two can be separated, which is exactly what extern is for - the declaration makes the name usable and the definition, elsewhere, allocates the storage. The other three statements are all true, including that shadowing in an inner scope is permitted.

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.

Is there any difference in the following declarations?
int myfun(int arr[]);
int myfun(arr[20]);

Answer: A

Correct answer: Yes

The first declares a parameter of pointer type, written as an unsized array, which is legal. The second gives a bare identifier and a size with no type at all, which is not a declaration and will not compile. A size in a parameter’s brackets is permitted but ignored - the parameter is a pointer either way.

Please log in or register to report this question.

18.

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.

19.

Which keyword is used to prevent any changes in the variable within a C program?

Answer: C

Correct answer: const

const tells the compiler the object is not to be modified through that name, and an attempt to assign to it is diagnosed. volatile is the opposite kind of promise - that the object may change by means the compiler cannot see - and mutable and immutable are not C keywords at all.

Please log in or register to report this question.

20.

A variable declared in a function can be used in main?

Answer: B

Correct answer: False

A variable declared inside a function has block scope and no linkage, so it does not exist as far as any other function is concerned. Declaring it static changes its lifetime but not its scope - it persists between calls while remaining invisible outside the function.

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