In: Computer Science
1. Select the answer that declares a variable named c that is a C character, initialized to the value A.
char *c = 'A';
char c = 'A';
char c = "A";
char *c = "A";
2. Fill in the missing code to produce the desired output:
int a = 0; int b = 1; int c; // Missing code goes here printf("%d", c);
Desired output:
1
-c = a && b;
-c = a || b;
-Answer not given
-c = a || !b;
3. What is the output of the following code segment:
int a = 1; int b = 2; int c = a + b; printf("%d", c);
-2
-3
-0
-1
4. You need to use printf() and scanf(). What line of code should you include in your code?
#include <stdio.h>
include stdio.h
#include "stdio.h"
import <stdio.h>
5. Select the C language built-in floating-point data types.
float, double
char, short, int, long
hex, float, double
float
6. What is the output of the following code:
int a = 1; int b = 2; if (a < b) { printf("A"); if (b < a) { printf("B"); } else { printf("C"); } }
-ABC
-A
-AB
-AC
7. Fill in the missing code to produce the desired output:
for (/*Missing code goes here*/) { printf("%d ", i); }
Desired output:
0 1 2
-int i = 1; i < 3; i++
-int i = 1; I <= 3; i++
-int i = 0; i < 3; i++
-Answer not listed
8. Suppose the following code tries to open a file that is not present. How do you handle the error condition?
FILE *f = fopen("exam.ext", "w"); if (/*Missing code goes here*/) { //Handle error condition here... }
-f == nil
-f == NULL
-f != NULL
-f != void
Rate my Solution and comment if any doubts
1:
-> option 2 is correct answer i.e..,
char c = 'A'; because it is character varaiable
named c which is
initialized to character 'A'.
-> option 1 is not correct because it
is a character pointer
-> option 3 is not correct because "A" represents a
string
-> option 4 is not correct because it
is a character pointer that points to a string
2:
-> option 2 ( 1 ) is
correct answer i.e.., 0 || 1 = 1 (False OR True = True)
-> option 1 is not correct answer
because (False AND True = False)
-> option 4 is not correct answer
because (False OR Not True ) is (False OR False = False )
-> option 3 is not correct as answer is
given
3:
-> option 2 which is 3
correct as 1 + 2 = 3
-> option 1 is not correct as 1 + 2 !=
2
-> option 3 is not correct as 1 + 2 !=
0
-> option 4 is not correct as 1 + 2 !=
1
4:
-> option 1 ( #include
<stdio.h>) is correct answer because it is
predefined header file .
option 3 (#include
"stdio.h") is also correct but it uses userdefined header
file.
-> option 2 and 4 are not correct as
it is not correct syntax
5:
-> option 1 is correct because both
float , double are predefined datatypes for
float
-> Remaining options are not correct as
they do not contain both float and double
6:
-> option 4 i.e.., AC
is corrrect because as a < b (1 < 2) is True so 'A' is
printed is first and then
b < a (2 < 1) is False So it
goes to else So 'C' is printed
-> option 1 is not correct as ABC
cannot be printed at once
-> option 2 is not correct as A only
cannot be printed
-> option 3 is not correct as AB cannot
be printed as a<b and b<a cannot be at the same time
7:
-> option 3 i.e.., (int i=0 ; i
< 3 ; i++) is correct because
first i=0 .. 0<3 and 0 will be
printed and i is incremented by 1then
i=1 .. 1<3 and 1 will be printed
and i is incremented by 1 then
i=2 .. 2<3 and 2 will be printed
and i is incremented by 1 then
i=3 .. 3<3 is false so loop will
break
-> option 1 is not correct as it gives
output 1,2
-> option 2 is not correct as
as 'I' is not declared
8:
-> option 2 (f==NULL)
is generally correct as f return NULL if there is no file
but if you opened a file in write mode which is not
exist then it automatically create that file
-> option 1 is not correct as nil is
notdefined
-> option 3 is not correct as if file
exist then it goes to if
-> option 4 is not correct as void is
the return type for the function