Question 1: Is there any difference int the following declarations?
int myfun(int arr[]);
int myfun(arr[20]);
1. True
rn2. False
rnAnswer: Option 1
rnYes, we have to specify the data type of the parameter when declaring a function.
rnQuestion 2: Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file f1 but used in files f2 and f3. In such a case would we need the extern declaration for the variables in the files f2 and f3?
rn1. True
rn2. False
rnAnswer: Option 1
rnYes, Consider,
rnvariable f1 in FILE1.C
variable f2 in FILE2.C
variable f3 in FILE3.C
If we need to use the variable f1 in the files FILE2.C and FILE3.C
we have to declare the variable f1 as extern int f1; in the files FILE2.C and FILE3.C.
Question 3: Global variable are available to all functions. Does there exist a mechanism by way of which it available to some and not to others.
rn1. True
rn2. False
rnAnswer: Option 2
rnThe only way this can be achieved is to define the variable locally in main() instead of defining it globally and then passing it to the functions which need it.
rnQuestion 4: Is it true that a global variable may have several declarations, but only one definition?
rn1. True
rn2. False
rnAnswer: Option 1
rnYes, in all the global variable declarations, you need to use the keyword extern.
rnQuestion 5: Is it true that a function may have several declarations, but only one definition?
rn1. True
rn2. False
rnAnswer: Option 1
rnYes, but the function declarations must be identical.
rnQuestion 6: How many times the while loop will get executed if a short int is 2 byte wide?
rn#include<stdio.h>
rnint main()
rn{
rnint j=1;
rnwhile(j <= 255)
rn{
rnprintf(“%c %dn”, j, j);
rnj++;
rn}
rnreturn 0;
rn}
rn1.Infinite times
rn2. 255 times
rn3. 256 times
rn4. 254 times
rnAnswer: Option 2
rnThe while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.
rnQuestion 7: Which of the following is not logical operator?
rn1. &
rn2. &&
rn3. ||
rn4. !
rnAnswer: Option 1
rnBitwise operators:
& is a Bitwise AND operator.
Logical operators:
&& is a Logical AND operator.
|| is a Logical OR operator.
! is a NOT operator.
So, ‘&’ is not a Logical operator.
rnQuestion 8: In mathematics and computer programming, which is the correct order of mathematical operators?
rn1 .Addition, Subtraction, Multiplication, Division
rn2. Division, Multiplication, Addition, Subtraction
rn3. Multiplication, Addition, Division, Subtraction
rn4. Addition, Division, Modulus, Subtraction
rnAnswer: Option 2
rnSimply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).
rnMnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, and Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.
rnQuestion 9: Which of the following cannot be checked in a switch-case statement?
rn1. Character
rn2. Integer
rn3. Float
rn4. enum
rnAnswer: Option 3
rnThe switch/case statement in the c language is defined by the language specification to use an int value, so you cannot use a float value.
rnQuestion 10: Point out the error, if any in the program.
rn#include<stdio.h>
rnint main()
rn{
rnint i = 1;
rnswitch(i)
rn{
rnprintf(“This is c program.”);
rncase 1:
rnprintf(“Case1”);
rnbreak;
rncase 2:
rnprintf(“Case2”);
rnbreak;
rn}
rnreturn 0;
rn}
rn1. Error: No default specified
rn2. Error: Invalid printf statement after switch statement
rn3. No Error and prints “Case1”
rn4. None of above
rnAnswer: Option 3
rnswitch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints “Case1”.
rnprintf(“This is c program.”); is ignored by the compiler.
rnHence there is no error and prints “Case1”.