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

Declarations and Initializations Questions and Answers

11.

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.

12.

Global variable are available to all functions. Does there exist a mechanism by way of which it available to some and not to others.

Answer: B

Correct answer: No

A name with external linkage is visible to every function that declares it, and nothing distinguishes one function from another. What can be restricted is the file: declaring the variable static at file scope confines it to that translation unit. The granularity is the file, not the function.

Please log in or register to report this question.

13.

Which of the following format identifier can never be used for the variable var?

int main()
{
char *var = "Advanced Training in C by AllIndiaExams.com";
}

Answer: A

Correct answer: %f

var is a pointer to char, so %s prints the string, and %d or %c could at least be applied to the pointer value or to a dereferenced character. %f expects a double and could never be given anything derived from this variable, which is what makes it the answer.

Please log in or register to report this question.

14.

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 is defined only for integer operands and will not compile with doubles. fmod from math.h is the floating point equivalent and returns 1.04 here. modf is unrelated - it splits a value into its integer and fractional parts.

Please log in or register to report this question.

15.

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

Answer: A

Correct answer: Yes

A prototype may appear in every file that calls the function, and usually does by way of a header, but the body is written once. The rule is the same as for objects: declarations may be repeated, and the definition may not.

Please log in or register to report this question.

16.

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.

17.

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.

18.

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.

19.

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.

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