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

C Constants Questions and Answers

21.

In C programming language, if the first and the second operands of operator + are of types int and float, respectively, the result will be of type

Answer: B

Correct answer: float

The usual arithmetic conversions apply: when the operands of a binary operator have different types, the one of lower rank is converted to the type of the other before the operation, and the result has that common type.

Here int is converted to float, so the addition is performed in floating point and the result is float. The rule is why integer division is such a common source of surprise - 1/2 is 0 because both operands are int, whereas 1/2.0 is 0.5.

Please log in or register to report this question.

22.

C programming language provides operations which deal directly with objects such as

Answer: C

Correct answer: characters, integers, and floating point numbers

C provides operations directly on the fundamental machine types - characters, integers and floating point numbers - because those are what the hardware supports.

It provides nothing built in for strings, sets, lists or dynamic arrays. A C string is only a convention: an array of characters terminated by a null, manipulated through library functions rather than through operators. This minimalism is deliberate, and it is what allows C to compile to efficient code on machines with very different capabilities.

Please log in or register to report this question.

Answer: D

Correct answer: no input and output facilities

The C language proper contains no input or output. There is no read or write statement and no I/O operator; printf and scanf are ordinary library functions, declared in stdio.h and linked like any others.

The separation is deliberate. Input and output are inherently machine- and system-dependent, so keeping them out of the language allows the language itself to be implemented on anything - including freestanding environments with no operating system and no console at all.

Please log in or register to report this question.

24.

The variables which can be accessed by all modules in a program, are called

Answer: D

Correct answer: global variables

Variables accessible to all modules of a program are global variables - declared at file scope with external linkage, so that any translation unit can refer to them by declaring them extern.

"External variable" is a near synonym and describes the same thing from the linkage side, but the term the question asks for is global. Local and internal variables are the opposite case: confined to the block or the translation unit in which they are declared.

Please log in or register to report this question.

Answer: A

Correct answer: int < unsigned < float < double

The usual arithmetic conversions promote towards the type of greater rank, and the ordering is int, then unsigned, then float, then double.

The int to unsigned step is the one that causes trouble in practice: comparing a negative int with an unsigned converts the negative value to a very large positive one, so -1 < 1u is false. The floating point steps are less treacherous, though converting a large long to float can lose precision.

Please log in or register to report this question.

26.

Consider the following statement
#define hypotenuse (a, b) sqrt (a*a + b*b);
The macro-call hypotenuse (a + 2, b + 3);

Answer: D

Correct answer: finds square root of 3*a + 4*b + 5

The macro's parameters are not parenthesised in the replacement text, so the arguments are substituted textually and the surrounding operators then bind more tightly than intended:

sqrt(a+2*a+2 + b+3*b+3)

which is \( \sqrt{a + 2a + 2 + b + 3b + 3} = \sqrt{3a + 4b + 5} \). The intended \( (a+2)^2 + (b+3)^2 \) is not what results. This is the standard argument for parenthesising every parameter and the whole replacement text in a function-like macro.

Please log in or register to report this question.

Answer: C

Correct answer: retains its value throughout the file of the program

A static variable has static storage duration: it is created before the program starts and destroyed when it ends, so it retains its value between calls to the function that declares it, and for the whole run of the program.

It can be initialised, though only with a constant expression, and its value can be changed freely at run time - what static fixes is its lifetime and, at file scope, its linkage, not its mutability. If no initialiser is given it is zero-initialised.

Please log in or register to report this question.

Answer: C

Correct answer: that certain information about mathematical library functions are to be included at the begnning of the program

#include <math.h> directs the preprocessor to insert the contents of the header at that point - the declarations of the mathematical library functions, along with any macros and types they need.

What it brings in is declarations, not the functions themselves: the code lives in the library and is joined at link time. Without the header the compiler would have to guess at the return types, and a call to sqrt would be assumed to return int, giving silently wrong results.

Please log in or register to report this question.

Answer: A

Correct answer: define men and women as 100 element floating point arrays

The typedef makes height a synonym for the type "array of 100 float", so declaring height men, women; declares two such arrays.

This is one of the cases where typedef earns its place: the array-of-100 part is bound to the type name, so both objects get it. Writing float men[100], women[100]; would be equivalent here, but with pointers the two forms diverge - typedef int *P; P a, b; makes both pointers, whereas int *a, b; does not.

Please log in or register to report this question.

Answer: A

Correct answer: leftmost bit is reserved for sign

A plain int is signed, and in the two's complement representation used by essentially every current implementation the most significant - leftmost - bit carries the sign: 0 for non-negative, 1 for negative.

That bit is not available for magnitude, which is why a 32-bit int spans roughly \( -2^{31} \) to \( 2^{31}-1 \) rather than 0 to \( 2^{32}-1 \). Declaring the variable unsigned releases the bit for magnitude and doubles the positive range.

Please log in or register to report this question.

Loading…

Other Subjects

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