Exercise :: Declarations and Initializations – General Questions
Declarations and Initializations – General Questions
Declarations and Initializations – Find Output of Program
Declarations and Initializations – Point Out Errors
Declarations and Initializations – Point Out Correct Statements
Declarations and Initializations – True / False Questions
Declarations and Initializations – Yes / No Questions
1.
Which of the following special symbol is allowed in a variable name?
A. * (asterisk)
B. | (pipeline)
C. – (hyphen)
D. _ (underscore)
Answer: Option D
Explanation:
Variable 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:
=> abc
=> abc123
=> ABC
=> abc_123
=> _abc
=> _123
Discussion Forum
2.
Is there any difference between following declarations?
1 : extern int fun();
2 : int fun();
A. Both are identical
B. No difference, except extern int fun(); is probably in another file
C. int fun(); is overrided with extern int fun();
D. None of these
Answer: Option B
Explanation:
extern int fun(); declaration in C is to indicate the existence of a global function and it is defined externally to the current module or in another file.
int fun(); declaration in C is to indicate the existence of a function inside the current module or in the same file.
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)
Answer: Option A
Explanation:
/* Example for ceil() and floor() functions: */
#include<stdio.h>
#include<math.h>
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
4.
In the following program where is the variable a getting defined and where it is getting declared?
#include<stdio.h>
int main()
{
extern int a;
printf(“%d\n”, a);
return 0;
}
int a=20;
A. extern int a is declaration, int a = 20 is the definition
B. int a = 20 is declaration, extern int a is the definition
C. int a = 20 is definition, a is not defined
D. a is declared, a is not defined
Answer: Option A
Explanation:
– During declaration we tell the datatype of the Variable.
– During definition the value is initialized.
5.
When do we mention the prototype of a function?
A. Defining
B. Declaring
C. Prototyping
D. Calling
Answer: 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.