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

Declarations and Initializations Questions and Answers

21.

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.

22.

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.

23.

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.

24.

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.

25.

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.

26.

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.

27.

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.

28.

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.

29.

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.

30.

Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file f1 but used in files f2 and f3. In such a case would we need the extern declaration for the variables in the files f2 and f3?

Answer: A

Correct answer: Yes

The definition lives in one file and reserves the storage; the other two files must be told that the name exists and what type it has, or the compiler has nothing to check their uses against. That is precisely what extern does, and the declaration is conventionally put in a header included by both.

Please log in or register to report this question.

Loading…

Other Subjects

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