Programming in C - UNIT I
53 flashcards · Programming Languages · by Kamala Viswanathan
Enumeration (or enum) is a ______ data type in C? A. user defined B. built-in C. libary D. None Of the above
A. user defined
A user defined data type, which is used to assign names to integral constants is called ___________. A. Union B. Array C. Structure D. Enum
D. Enum
If we do not explicitly assign values to enum names, the compiler by default assigns values to ? A. null B. -1 C. 0 D. Garbage
C. 0 If we do not explicitly assign values to enum names, the compiler by default assigns values to 0.
All enum constants are? A. Same in their scope B. unique in their scope C. contain dupicate value in their scope D. None of the above
B. unique in their scope All enum constants must be unique in their scope.
String handling functions such as strcmp(), strcpy() etc can be used with enumerated types. A. TRUE B. FALSE C. May Be D. Can't Say
B. FALSE Enumerated types are not strings. Hence it is not possible to use string handling functions with enumerated data types.
Pick the incorrect statement with respect to enums. A. Two enum symbols cannot have the same value B. Only integer constants are allowed in enums C. It is not possible to change the value of enum symbols D. Enum variables are automatically assigned values if no value is specified
A. Two enum symbols cannot have the same value The statement that two enum symbols cannot have the same value is incorrect. Any number of enum symbols can have the same value.
Arithmetic operations are not allowed on enumerated constants. A. TRUE B. FALSE C. May Be D. Can't Say
B. FALSE Arithmetic operations such as addition, subtraction, multiplication and division are allowed on enumerated constants.
What is the correct syntax of enum? A. enum flag{constant1, constant2, constant3, ....... }; B. enum flag(constant1, constant2, constant3, ....... ); C. enum flag[constant1, constant2, constant3, ....... ]; D. enumflag{constant1, constant2, constant3, ....... };
The correct syntax of enum is enum flag{constant1, constant2, constant3, ....... };
What is the output of the following code? #include<stdio.h> enum colour { blue, red, yellow }; main() { enum colour c; c=yellow; printf("%d",c); } a) 1 b) 2 c) 0 d) Error
b) 2 Enum variables are automatically assigned values if no value is specified. The compiler by default assigns values starting from 0. Therefore, in the above code, blue gets 0, red gets 1 and yellow gets 2.
What will be the output of the following C code? #include<stdio.h> enum hello { a,b=99,c,d=-1 }; main() { enum hello m; printf("%d\n%d\n%d\n%d\n",a,b,c,d); } a) 1 99 100 -1 b) Error c) 0 99 100 -1 d) 0 1 2 3
c) 0 99 100 -1
Which of the following operators has an associativity from Right to Left? a) <= b) << c) == d) +=
d) +=
Which operators of the following have same precedence? P. "!=", Q. "+=", R. "<<=" a) P and Q b) Q and R c) P and R d) P, Q and R
b) Q and R
Which of the following is correct Associativity for == operator? A. Left to right B. Right to left C. Left to left D. Right to right
A. Left to right
Which of the following operator has highest Precedence? A. * B. / C. ~ D. [ ]
D. [ ]
Which of the following operator has lowest Precedence? A. || B. , C. ?: D. =
D. =
Which of the following is a ternary operator? A. || B. && C. ?: D. >>
C. ?:
What will be output for the following code? #include <stdio.h> int main() { int a = 1, b = 2; int c = a ^ b & 1; printf("%d", c); } A. 0 B. 1 C. 2 D. 3
B. 1
What will be output for the following code? #include <stdio.h> int main() { double a = 5 % 3 & 4 + 5 * 6; printf("%lf", a); } A. 2 B. 30 C. 2.000000 D. Run-time error
C. 2.000000
Which of the following has same Precedence? A. ++ B. -> C. ! A. A and B B. B and C C. A and C D. All has same Precedence
A. A and B
Which of the following option is the correct representation of the following C statement? e = a * b + c / d * f; A. e = (a * (b +(c /(d * f)))); B. e = ((a * b) + (c / (d * f))); C. e = ((a * b) + ((c / d)* f)); D. Both C and B
D. Both C and B
Which of the following method is accepted for assignment? a) 5 = a = b = c = d; b) a = b = c = d = 5; c) a = b = 5 = c = d; d) None of the mentioned
b) a = b = c = d = 5;
Which of the following is NOT possible with any 2 operators in C? a) Different precedence, same associativity b) Different precedence, different associativity c) Same precedence, different associativity d) All of the mentioned
c) Same precedence, different associativity
Which of the following is possible with any 2 operators in C? a) Same associativity, different precedence b) Same associativity, same precedence c) Different associativity, different precedence d) All of the mentioned
d) All of the mentioned
Which of the following operators has the lowest precedence? a) != b) && c) ?: d) ,
d) ,
What will be the output of the following C code? #include <stdio.h> int main() { int x = 3, i = 0; do { x = x++; i++; } while (i != 3); printf("%d\n", x); } a) Undefined behaviour b) Output will be 3 c) Output will be 6 d) Output will be 5
b) Output will be 3
What will be the output of the following C code? #include <stdio.h> int main() { int a = -1, b = 4, c = 1, d; d = ++a && ++b || ++c; printf("%d, %d, %d, %d\n", a, b, c, d); return 0; } a) 0, 4, 2, 1 b) 0, 5, 2, 1 c) -1, 4, 1, 1 d) 0, 5, 1, 0
a) 0, 4, 2, 1
What will be the output of the following C code? #include <stdio.h> int main() { int p = 10, q = 20, r; if (r = p = 5 || q > 20) printf("%d", r); else printf("No Output\n"); } a) 1 b) 10 c) 20 d) No Output
a) 1
Choose a right C Statement. a) Loops or Repetition block executes a group of statements repeatedly b) Loop is usually executed as long as a condition is met c) Loops usually take advantage of Loop Counter d) All the above
d) All the above
Loops in C Language are implemented using? a) While Block b) For Block c) Do While Block d) All the above
d) All the above
Which loop is faster in C Language, for, while or Do While? a) for b) while c) do while d) All work at same speed
d) All work at same speed
If block always need to be assoicated with a else block? a) True b) False
b) False
Which of the following is binary operator? a) && b) || c) both i & ii d) !
! is a binary operator.
The conditional operator are also known as a) Relational operator b) Binary operator c) Ternary operator d) Arithmetic operator
c) Ternary operator
What will be the value of y if x = 8? y = (x > 6 ? 4 : 6); a) Compilation Error b) 0 c) 4 d) 6
c) 4
Which of the following operator reverses the result of expression it operators on a) ! b) || c) && d) All of the above
a) !
If you have to make decision based on multiple choices, which of the following is best suited? a) if b) if-else c) if-else-if d) All of the above
c) if-else-if
The continue statment cannot be used with ________ a) for b) while c) do while d) switch
d) switch
Which keyword can be used for coming out of recursion? a) return b) break c) exit d) both A and B
a) return
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)){}
a) if (if (a == 1)){}
Switch statement accepts a) int b) char c) long d) All of the above
d) All of the above
A labeled statement consist of an identifier followed by a) ; b) : c) , d) =
b) : The label is an identifier. When goto statement is encountered, control of the program jumps to label and starts executing the code.
Which loop is guaranteed to execute at least one time? a) for b) while c) do while d) None of the above
c) do while
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
d) All of these
Choose a right C Statement. A) Loops or Repetition block executes a group of statements repeatedly. B) Loop is usually executed as long as a condition is met. C) Loops usually take advantage of Loop Counter D) All the above.
D) All the above.
Loops in C Language are implemented using.? A) While Block B) For Block C) Do While Block D) All the above
D) All the above
Which loop is faster in C Language, for, while or Do While.? A) for B) while C) do while D) All work at same speed
D) All work at same speed
Choose correct C while loop syntax. a) while(condition) { //statements } b) { //statements }while(condition) c) while(condition); { //statements } d) while() { if(condition) { //statements } }
a) while(condition) { //statements }
Choose a correct C for loop syntax. a) for(initalization; condition; incrementoperation) { //statements } b) for(declaration; condition; incrementoperation) { //statements } c) for(declaration; incrementoperation; condition) { //statements } d) for(initalization; condition; incrementoperation;) { //statements }
a) for(initalization; condition; incrementoperation) { //statements }
Choose a correct C do while syntax. a) dowhile(condition) { //statements } b) do while(condition) { //statements } c) do { //statements }while(condition) d) do { //statements }while(condition);
d) do { //statements }while(condition);
What is the output of C Program? int main() { while(true) { printf("RABBIT"); break; } return 0; } A) RABBIT B) RABBIT is printed unlimited number of times. C) No output D) Compiler error.
D) Compiler error. while(TRUE) or while(true) does not work. true is not a keyword.
What is the output of C Program? int main() { int a=5; while(a==5) { printf("RABBIT"); break; } return 0; } A) RABBIT is printed unlimited number of times B) RABBIT C) Compiler error D) None of the above.
B) RABBIT If there is no BREAK statement, while loop runs continuously util the computer hangs. BREAK causes the loop to break once and the statement below the while if any will be executed.
What is the output of C Program? int main() { int a=5; while(a=123) { printf("RABBIT\n"); break; } printf("GREEN"); return 0; } A) GREEN B) RABBIT GREEN C) RABBIT is printed unlimited number of times. D) Compiler error.
B) RABBIT GREEN while(a=123) = while(123) = while(Non Zero Number). So while is executed. BREAK breaks the loop immediately. Without break statement, while loop runs infinite number of times.
What is the output of C Program? int main() { int a=32; do { printf("%d ", a); a++; }while(a <= 30); return 0; } A) 32 B) 33 C) 30 D) No Output
A) 32 do { } block is executed even before checking while(condition) at least once. This prints 32. To loop for the second time, while (32 <= 30) fails. So, loop is quit.