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

C Constants Questions and Answers

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.

Answer: D

Correct answer: All of the above

All three are true. An array holds one type. An array may be a member of a structure, as a fixed-length name field commonly is. And an array of structures is entirely ordinary - a table of records is exactly that.

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.

24.

By default, any real number in 'C' is treated as

Answer: B

Correct answer: A double

An unsuffixed floating constant such as 3.14 has type double in C. To obtain a float the suffix f is required - 3.14f - and L gives a long double.

The default matters in arithmetic: writing float x = 1.0/3.0; performs the division in double precision and only then narrows the result, which is usually what is wanted. It also matters for performance on hardware where single precision is faster, since the double constant forces the whole expression up.

Please log in or register to report this question.

25.

Constants in C can be divided into categories ?

Answer: C

Correct answer: 2

C constants are conventionally divided into two categories: primary and secondary.

Primary constants are the fundamental values - integer, real and character constants. Secondary constants are those built from them, covering arrays, pointers, structures, unions and enumerations. The division mirrors the distinction between primitive and derived data types, and it is a teaching taxonomy rather than a distinction the language standard itself draws.

Please log in or register to report this question.

Answer: D

Correct answer: All of the above

All three statements hold. A wide character is a binary representation of a character from an extended set, wide enough to hold members of the largest supported character set - which is what allows scripts beyond a single-byte encoding to be represented.

Its type is wchar_t, an integer type defined in stddef.h, and the wide-character input functions signal end of file by returning WEOF, the wide analogue of EOF. The wide-character library mirrors the ordinary one throughout, with wcslen for strlen and so on.

Please log in or register to report this question.

27.

What is the output of this C code?

int main()
{
int var = 010;
printf("%d", var);
}

 

Answer: B

Correct answer: 8

A numeric literal beginning with 0 is octal in C, so 010 is 8 in decimal, not 10.

\[ 010_8 = 1 \times 8^1 + 0 \times 8^0 = 8 \]

This is a well-known source of bugs, particularly where numbers are padded to a fixed width - a date field written as 08 or 09 is not even valid octal and fails to compile, while 010 compiles and silently means 8. Hexadecimal requires the explicit 0x prefix, but octal needs only the leading zero.

Please log in or register to report this question.

28.

To print out a and b given below, which printf() statement would you use?

float a = 3.14;
double b = 3.14;

Answer: A

Correct answer: printf("%f%f",a,b);

Both are printed with %f. In a call to a variadic function such as printf, the default argument promotions apply, and a float argument is promoted to double before it is passed - so printf receives two doubles and %f is correct for each.

There is therefore no %f for float and separate specifier for double; %f serves both. %Lf is for long double, and using it here would misread the argument and produce nonsense.

Please log in or register to report this question.

Answer: D

Correct answer: Enum constant

The primary constants are integer, real and character constants - the three fundamental kinds of value written directly in source.

An enumeration constant is classed as secondary, since it is built on the integer type rather than being a distinct kind of literal in its own right. In the same classification, arrays, pointers, structures and unions are also secondary, being composed from the primary types.

Please log in or register to report this question.

30.

The library function sqrt operates on a double precision argument. If, i is an integer variable, then which of the following calls would correctly compute sqrt(i)?

Answer: A

Correct answer: sqrt((double)i)

The cast must be applied to the argument, before the call, so that the value passed has the type the function expects.

In practice a prototype from math.h would convert i automatically, so sqrt(i) also works when the header is included - but the explicit cast is correct regardless and states the intent. Casting the result, as the other options do, is too late: it converts a value the function has already computed, and without a prototype the argument would have been passed as an int and misinterpreted.

Please log in or register to report this question.

Loading…
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