MSBTE I Scheme CM/IF Branch Practice MCQs of “Programming In C (22226)”
UNIT-2. Basics Of C Programming.
1. How many keywords are there in c ?
A. 31
B. 32
C. 64
D. 63
Ans : B
Explanation: There are total 32 keywords in C.Keywords are those words whose meaning is already defined by Compiler.C Keywords are also called as Reserved words.
2. Which of the following is true for variable names in C?
A. Variable names cannot start with a digit
B. Variable can be of any length
C. They can contain alphanumeric characters as well as special characters
D. Reserved Word can be used as variable name
Ans : A
Explanation: Variable names cannot start with a digit in C Programming language.
3. Which of the following cannot be a variable name in C?
A. TRUE
B. friend
C. export
D. volatile
Ans : D
Explanation: volatile is C keyword.Volatile in C programming language signify that the compiler that the software in hand (the thread for the routine it’s compiling) doesn’t have exclusive control over the variable described as "volatile"
4. What is the output of this program?
void main()
{
int x = 10;
float x = 10;
printf("%d", x)
}
A. Compilations Error
B. 10
C. 10
D. 10.1
Ans : A
Explanation: Since the variable x is defined both as integer and as float, it results in an error.
5. What is the output of this program?
#include <stdio.h>
int main()
{
int i;
for (i = 0;i < 5; i++)
int a = i;
printf("%d", a);
}
A. Syntax error in declaration of a
B. No errors, program will show the output 5
C. Redeclaration of a in same scope throws error
D. a is out of scope when printf is called
Ans : A
Explanation: the output of this program is the Syntax error in declaration of variable a.
6. What is the output of this program?
#include <stdio.h>
int var = 20;
int main()
{
int var = var;
printf("%d ", var);
return 0;
}
A. Garbage Value
B. 20
C. Compiler Error
D. None of these
Ans : A
Explanation: First var is declared, then value is assigned to it. As soon as var is declared as a local variable, it hides the global variable var.
7. What is the output of this program?
void main()
{
int p, q, r, s;
p = 1;
q = 2;
r = p, q;
s = (p, q);
printf("p=%d q=%d", p, q);
}
A. p=1 q=1
B. p=1 q=2
C. p=2 q=2
D. Invalid Syntex
Ans : B
Explanation: The comma operator evaluates both of its operands and produces the value of the second. It also has lower precedence than assignment. Hence r = p, q is equivalent to r = p, while s = (p, q) is equivalent to s = q.
8. What is the output of this program?
void main()
{
printf("%x",-1<<4);
}
A. fff0
B. fff1
C. fff2
D. fff3
Ans : A
Explanation: -1 will be represented in binary form as: 1111 1111 1111 1111 Now -1<<4 means 1 is Shifted towards left by 4 positions, hence it becomes: 1111 1111 1111 0000 in hexadecimal form - fff0.
9. What is the output of this program?
#include <stdio.h>
void main()
{
int a=1, b=2, c=3, d;
d = (a=c, b+=a, c=a+b+c);
printf("%d %d %d %d", d, a, b, c);
}
A. 11 3 5 11
B. 11 1 5 11
C. 11 3 2 11
D. 11 3 3 11
Ans : A
Explanation: For any comma separated expression the outcome is the right most part.
10. What is the output of this program?
void main()
{
int a, b = 5, c;
a = 5 * (b++);
c = 5 * (++b);
printf("%d %d",a,c);
}
A. 30 35
B. 30 30
C. 25 30
D. 25 35
Ans : D
Explanation: a = 5 * 5 and b = 5 * 7
11. What is size of int in C ?
A. 2 bytes
B. 4 bytes
C. 8 bytes
D. Depends on the system/compiler
Ans : D
Explanation: The size of the datatypes depend on the system.The size of "int", in fact every other data type as well is compiler dependent and not language dependent. Based on how a compiler is implemented, it can take either 2 bytes or 4 bytes.
12. Range of double is -1.7e-38 to 1.7e+38 (in 16 bit platform - Turbo C under DOS)
A. TRUE
B. FALSE
C. May Be
D. Can't Say
Ans : B
Explanation: The range of double is -1.7e+308 to 1.7e+308.
13. Which is false?
A. Constant variables need not be defined as they are declared and can be defined later
B. Global constant variables are initialized to zero
C. const keyword is used to define constant values
D. You cannot reassign a value to a constant variable
Ans : A
Explanation: Since the constant variable has to be declared and defined at the same time, not doing it results in an error..
14. Array is ______ datatype in C Programming language.
A. Derived Data type
B. Primitive Data type
C. Custom Data type
D. None of these
Ans : A
Explanation: Data types simply refers to the type and size of data associated with variables and functions.It is of two types :- Fundamental Data Types and Derived Data Types. Array is Derived Data type datatype in C Programming language.
15. If you pass an array as an argument to a function, what actually gets passed?
A. Address of last element of Array
B. Value of first element
C. Base address of array
D. Value of elements in array
Ans : C
Explanation: Base address of array is passed.
16. When double is converted to float, the value is?
A. Rounded
B. Truncated
C. Depends on the standard
D. Depends on the compiler
Ans : D
Explanation: When double is converted to float, the value will be Depends on the compiler.
17. Which of the following is not a logical operator?
A. !
B. &&
C. ||
D. |
Ans : D
Explanation: && - Logical AND ! - Logical NOT || - Logical OR | - Bitwise OR(used in bitwise manipulations)
18. What is the output of this program?
#include <stdio.h>
int main(){
printf("%d",EOF);
return 0;
}
A. 0
B. 1
C. -1
D. NULL
Ans : C
Explanation: EOF is macro which has been defined in stdio.h and it is equivalent to -1.
19. What is the output of this program?
#include <stdio.h>
int main(){
char num = '10';
printf("%d", num);
return 0;
}
A. 49
B. 48
C. 10
D. 8
Ans : B
Explanation: It will print the ascii value of 0, i.e it will print the ascii value of last character always
20. What is the output of this program?
#include <stdio.h>
int main(){
void num=10;
printf("%v", num);
return 0;
}
A. Compilation error
B. 10
C. Garbage value
D. 0
Ans : A
Explanation: Void is not a valid data type for declaring variables.
1. In the following loop construct, which one is executed only once always.    for(exp1; exp2; exp3)
A. exp1
B. exp3
C. exp1 and exp3
D. exp1, exp2 and exp3
Ans : A
Explanation: Expression exp1 is executed only once since this is used for initialization
2. The continue statment cannot be used with
A. for
B. while
C. do while
D. switch
Ans : D
Explanation: continue is used to skip the statments and can not be used with switch
3. Which keyword can be used for coming out of recursion?
A. return
B. break
C. exit
D. both A and B
Ans : A
Explanation: Return is used for coming out of recursion
4. goto can be used to jump from main to within a function?
A. TRUE
B. FALSE
C. May Be
D. Can't Say
Ans : B
Explanation: goto statement in C programming provides an unconditional jump from the 'goto' to a labeled statement in the same function.
5. Which of the following is an invalid if-else statement?
A. if (if (a == 1)){}
B. if (a){}
C. if ((char) a){}
D. if (func1 (a)){}
Ans : A
Explanation: None
6. Switch statement accepts.
A. int
B. char
C. long
D. All of the above
Ans : D
Explanation: switch statment accepts all int , char and long .
7. Which loop is guaranteed to execute at least one time.
A. for
B. while
C. do while
D. None of the above
Ans : C
Explanation: In do while first the statements in the body are executed then the condition is checked. If the condition is true then once again statements in the body of do while are executed.
8. A labeled statement consist of an identifier followed by
A. ;
B. :
C. ,
D. =
Ans : B
Explanation: The label is an identifier. When goto statement is encountered, control of the program jumps to label: and starts executing the code.
9. do-while loop terminates when conditional expression returns?
A. One
B. Zero
C. Non - zero
D. None of the above
Ans : B
Explanation: zero indicate False which terminate the loop .
10. c = (n) ? a : b; can be rewritten asexp1 ? exp2 : exp3;
A. if(n){c = a;}else{c = b;}
B. if(!n){c = a;}else{c = b;}
C. if(n){c = b;}else{c = a;}
D. None of the above
Ans : A
Explanation: None.
11. For loop in a C program, if the condition is missing?
A. it is assumed to be present and taken to be false
B. it is assumed to be present and taken to the true
C. it result in a syntax error
D. execution will be terminated abruptly
Ans : B
Explanation: None
12. Which of the following statement about for loop is true ?
A. Index value is retained outside the loop
B. Index value can be changed from within the loop
C. Goto can be used to jump, out of the loop
D. All of these
Ans : D
Explanation: None
13. Using goto inside for loop is equivalent to using
A. Continue
B. Break
C. Return
D. None of the above
Ans : D
Explanation: Goto statement is rarely used in loops,we can not use continue,break & return instead of goto.
14. If switch feature is used, then
A. Default case must be present
B. Default case, if used, should be the last case
C. Default case, if used, can be placed anywhere
D. None of the above
Ans : C
Explanation: None
15. Which of the following comments about for loop are correct ?
A. Using break is equivalent to using a goto that jumps to the statement immediately following the loop
B. Continue is used to by-pass the remainder of the current pass of the loop
C. If comma operator is used, then the value returned is the value of the right operand
D. All of the above
Ans : D
Explanation: None
16. In the context of "break" and "continue" statements in C, pick the best statement.
A. "break" and "continue" can be used in "for", "while", "do-while" loop body and "switch" body.
B. "break" and "continue" can be used in "for", "while" and "do-while" loop body. But only "break" can be used in "switch" body.
C. "break" and "continue" can be used in "for", "while" and "do-while" loop body. Besides, "continue" and "break" can be used in "switch" and "if-else" body.
D. "break" can be used in "for", "while" and "do-while" loop body.
Ans : B
Explanation: As per C standard, "continue" can be used in loop body only. "break" can be used in loop body and switch body only. That's why correct answer is B.
17. In _______, the bodies of the two loops are merged together to form a single loop provided that they do not make any references to each other.
A. Loop unrolling
B. Strength reduction
C. Loop concatenation
D. Loop jamming
Ans : D
Explanation: In loop jamming, the bodies of the two loops are merged together to form a single loop provided that they do not make any references to each other.
18. What is the output of this program?
void main()
{
if(!printf(""))
printf("hello");
else
printf("world");
}
A. hello
B. world
C. Compilation Error
D. None of the above
Ans : A
Explanation: printf(") will return 0 and therefore !printf(") is equal to 1 so if part will execute .
19. What is the output of this program?
#include <stdio.h>
void main()
{
int a=10;
if(a=5)
printf("YES");
else
printf("NO");
}
A. YES
B. NO
C. Error
D. None of the above
Ans : A
Explanation: we have assigned a = 5 , now the statment becomes if(5) which is true therefore YES will be printed .
20. What is correct about the given program?
#include <stdio.h>
int x;
void main()
{
if (x);
else
printf("Else");
}
A. if block will be executed
B. else block will be executed
C. Depends on value of x since it is undeclared
D. Compilation Error
Ans : B
Explanation: Since x is globally defined, it is initialized with default value 0. The Else block is executed as the expression within if evaluates to FALSE.