Declarations and Initializations Questions and Answers

Exercise

Exercise 1
Exercise 2

Article

Q 1
Which of the following special symbol allowed in a variable name?

A)   * (asterisk)

B)   | (pipeline)

C)   - (hyphen)

D)   _ (underscore)


Correct Option - D

ExplanationVariable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit. Examples of valid (but not very descriptive) C variable names: => foo => Bar => BAZ => foo_bar => _foo42 => _ => QuUx

Report this question

Q 2
Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

A)   rem = 3.14 % 2.1;

B)   rem = modf(3.14, 2.1);

C)   rem = fmod(3.14, 2.1);

D)   Remainder cannot be obtain in floating point division.


Correct Option - C

Explanationfmod(x,y) - Calculates x modulo y, the remainder of x/y. This function is the same as the modulus operator. But fmod() performs floating point divisions.

Report this question

Q 3
How would you round off a value from 1.66 to 2.0?

A)   ceil(1.66)

B)   floor(1.66)

C)   roundup(1.66)

D)   roundto(1.66)


Correct Option - A

Explanation


Report this question

Q 4
What are the types of linkages?

A) Internal and External

B) External, Internal and None

C) External and None

D) Internal


Correct Option - B

Explanation

External Linkage-> means global, non-static variables and functions.

Internal Linkage-> means static variables and functions with file scope.

None Linkage-> means Local variables.

Report this question

Q 5
How would you round off a value from 1.66 to 2.0?

A)   ceil(1.66)

B)   floor(1.66)

C)   roundup(1.66)

D)   roundto(1.66)


Correct Option - A

Explanation

/* Example for ceil() and floor() functions: */

#include
#include

int main()
{
    printf("\n Result : %f" , ceil(1.44) );
    printf("\n Result : %f" , ceil(1.66) );
 
    printf("\n Result : %f" , floor(1.44) );    
    printf("\n Result : %f" , floor(1.66) );

    return 0;
}
// Output:
// Result : 2.000000
// Result : 2.000000
// Result : 1.000000
// Result : 1.000000

Report this question

Q 6
When we mention the prototype of a function?

A)   Defining

B)   Declaring

C)   Prototyping

D)   Calling


Correct Option - B

Explanation

A function prototype in C or C++ is a declaration of a function that omits the function body but does specify the function's name, argument types and return type.

While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface.

Report this question

Q 7
Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

A)   rem = 3.14 % 2.1;

B)   rem = modf(3.14, 2.1);

C)   rem = fmod(3.14, 2.1);

D)   Remainder cannot be obtain in floating point division


Correct Option - C

Explanation

fmod(x,y) - Calculates x modulo y, the remainder of x/y.

This function is the same as the modulus operator. But fmod() performs floating point divisions.

Report this question


Share This Page -