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

C Constants Questions and Answers

11.

Comment on the output of this C code?

int const print()
{
printf("AllIndiaExams.in");
return 0;
}
void main()
{
print();
}

 

Answer: B

Correct answer: AllIndiaExams.in

The program prints the string once and stops. Applying const to a function's return type simply qualifies the value returned; for a return type of int it has no practical effect at all, since the returned value is a copy that the caller here discards.

Nothing in the code causes repetition - print() is called once from main and returns 0. The trap is reading int const print() as something exotic; it is an ordinary function with a redundant qualifier.

Please log in or register to report this question.

Answer: D

Correct answer: all of these

All three statements describe an external variable. It has file scope and external linkage, so it is accessible from every function in the program, including functions in other translation units that declare it with extern.

It has a declaration, and it has static storage duration, so if no initialiser is given it is zero-initialised before the program starts rather than holding a garbage value. That last property distinguishes it sharply from an automatic variable, whose uninitialised value is indeterminate.

Please log in or register to report this question.

13.

The declaration "unsigned u" indicates u is a/an

Answer: B

Correct answer: unsigned integer

In C the type specifiers may be abbreviated, and unsigned alone means unsigned int. Similarly signed alone, short alone and long alone all mean the corresponding int type.

An unsigned character would have to be written unsigned char, which is a distinct type - and one that must be written out in full, since char is the only type whose signedness is implementation-defined and which therefore has three distinct spellings.

Please log in or register to report this question.

Answer: C

Correct answer: which may require less storage than normal integers

short int requests an integer type that occupies no more storage than int, and typically less - commonly 2 bytes against 4. The standard guarantees only a minimum range and the ordering short ≤ int ≤ long, not any particular size.

The name refers to storage, not to the variable's lifetime or the length of its identifier. It is used where memory matters - in large arrays or in structures mapped onto a hardware or file format - at the cost of a narrower range.

Please log in or register to report this question.

15.

Which of the following 'C' type is not a primitive data structure?

Answer: D

Correct answer: none of these

All three named types are primitive: int, float and char are built into the language, each with a fixed representation and a defined set of operations, and none is composed of other types.

So none of them is the exception the question asks for. Non-primitive, or derived, types are those built from primitives - arrays, structures, unions, pointers and functions - and it is those that would answer the question had one been offered.

Please log in or register to report this question.

Answer: C

Correct answer: prints a value that is implementation dependent

Printing a character as an integer prints its character code, and the result depends on the implementation in two ways. The character set is not fixed by the standard, though ASCII is near-universal in practice; and more importantly, whether char is signed or unsigned is implementation-defined.

So a character with the high bit set - beyond the basic character set - prints as a positive value on an implementation where char is unsigned and a negative one where it is signed. This is why signed char or unsigned char is used explicitly wherever the value matters.

Please log in or register to report this question.

17.

The program fragment
int i = 263 ;
putchar (i) ;
prints

Answer: C

Correct answer: rings the bell

putchar takes an int but converts it to unsigned char before writing, so only the low-order byte survives:

\[ 263 \bmod 256 = 7 \]

Character code 7 is BEL, the alert character, so the terminal sounds its bell rather than printing anything. The lesson is general: passing a value outside the range of unsigned char to putchar is not an error but a silent truncation, and the character actually written is whatever the low byte encodes.

Please log in or register to report this question.

Answer: C

Correct answer: repeated execution may result in different addresses for i

The declaration int i = 5; inside a function creates an object with automatic storage duration: it is allocated when the block is entered and released when it is left.

Nothing fixes where. A recursive call, a different call path, or simply a different run of the program can place it at a different address, and modern systems randomise the stack deliberately. Within a single lifetime the address is stable and the value may change; across lifetimes neither the address nor the value carries over.

Please log in or register to report this question.

19.

If the declaration unsigned c:5; is replaced by unsigned : 6; then

Answer: C

Correct answer: compiler will give a new name for the field

A bit-field declared without a name - unsigned : 6; - is an unnamed bit-field, which is legal C. It reserves the stated number of bits as padding but provides no name by which they can be accessed.

Its purpose is layout control: unnamed fields are used to align the following members at a particular bit position when a structure is mapped onto a hardware register or a defined external format. A width of zero has a further special meaning, forcing the next field to begin at the next storage unit.

Please log in or register to report this question.

20.

The value of ab if ab & 0 x 3f equals 0 x 27 is

Answer: D

Correct answer: 0 x 27

The mask 0x3f is 00111111 in binary, so ab & 0x3f keeps the low six bits of ab and clears the rest. For the result to be 0x27, those six bits must be 100111.

Of the values offered, 0x27 itself satisfies this, since 0x27 & 0x3f = 0x27. Note that the condition does not determine ab uniquely - any value agreeing in the low six bits, such as 0x67 or 0xa7, would also satisfy it - but only 0x27 appears among the options.

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