Академический Документы
Профессиональный Документы
Культура Документы
In a file contains the line "I am a boy\r\n" then on reading this line
into the array strusing fgets(). What will str contain?
A.
"I am a boy\r\n\0"
B.
"I am a boy\r\0"
C.
"I am a boy\n\0"
D.
"I am a boy"
Answer: Option C
Explanation:
Declaration: char *fgets(char *s, int n, FILE *stream);
fgets reads characters from stream into the string s. It stops when it
reads either n - 1 characters or a newline character, whichever comes
first.
Therefore, the string str contain "I am a boy\n\0"
2.
Explanation:
This program tries to open the file trial.txt in read mode. If file not
exists or unable to read it prints "Unable to open file" and then
terminate the program.
If file exists, it simply close the file and then terminates the program.
B.
C.
Error: in free(ptr);
D.
No error
Answer: Option B
Explanation:
Answer: ptr = (char*)malloc(30);
inti=0;
for(; i<=5; i++);
printf("%d", i);
return0;
}
A.
0, 1, 2, 3, 4, 5
B.
C.
1, 2, 3, 4
D.
Answer: Option D
Explanation:
Step 1: inti = 0; here variable i is an integer type and initialized to '0'.
Step 2: for(; i<=5; i++); variable i=0 is already assigned in previous
step. The semi-colon at the end of this for loop tells, "there is no more
statement is inside the loop".
Loop 1: here i=0, the condition in
then i is incremented by '1'(one)
Loop 2: here i=1, the condition in
then i is incremented by '1'(one)
Loop 3: here i=2, the condition in
then i is incremented by '1'(one)
Loop 4: here i=3, the condition in
then i is increemented by '1'(one)
Loop 5: here i=4, the condition in
then i is incremented by '1'(one)
Loop 6: here i=5, the condition in
then i is incremented by '1'(one)
Loop 7: here i=6, the condition in
then i is not incremented.
inti;
i = printf("Howru\n");
i = printf("%d\n", i);
printf("%d\n", i);
return0;
}
A.
How r u
7
2
B.
How r u
8
2
C.
How r u
1
1
D.
Error: cannot
assign printf to variable
Answer: Option B
Explanation:
In the program, printf() returns the number of charecters printed on
the console
i = printf("How r u\n"); This line prints "How r u" with a new line
character and returns the length of string printed then assign it
to variable i.
So i = 8 (length of '\n' is 1).
i = printf("%d\n", i); In the previous step the value of i is 8. So it
prints "8" with a new line character and returns the length of string
printed then assign it tovariablei. So i = 2 (length of '\n' is 1).
printf("%d\n", i); In the previous step the value of i is 2. So it prints
"2".
b = 300 c = 200
B.
b = 100 c = garbage
C.
b = 300 c = garbage
D.
b = 100 c = 200
Answer: Option D
Explanation:
Initially variables a = 500, b = 100 and c is not assigned.
Step 1: if(!a >= 400)
Step 2: if(!500 >= 400)
Step 3: if(0 >= 400)
Step 4: if(FALSE) Hence the if condition is failed.
Step 5: So, variable c is assigned to a value '200'.
Step 6: printf("b = %d c = %d\n", b, c); It prints value of b and c.
Hence the output is "b = 100 c = 200"
2.
sizeof
3.
4.
&&
A.
1, 2
B.
1, 3
C.
2, 4
D.
1, 2, 3
Answer: Option D
Explanation:
An operation with only one operand is called unary operation.
Unary operators:
! Logical NOT operator.
~ bitwise NOT operator.
sizeof Size-of operator.
&& Logical AND is a logical operator.
Therefore, 1, 2, 3 are unary operators.
-2, 3, 1, 1
B.
2, 3, 1, 2
C.
1, 2, 3, 1
D.
3, 3, 1, 2
Answer: Option A
Explanation:
Step 1: inti=-3, j=2, k=0, m; here variable i, j, k, m are declared
as an integer type and variable i, j, k are initialized to -3, 2, 0
respectively.
Step 2: m = ++i&& ++j && ++k;
becomes m = -2 && 3 && 1;
Print 5, 4, 3, 2, 1
B.
Print 1, 2, 3, 4, 5
C.
Print 5, 4, 3, 2, 1, 0
D.
Infinite loop
Answer: Option D
Explanation:
Step 1: int no=5; The variable no is declared as integer type and
initialized to 5.
B.
C.
Infinite loop
D.
Prints "Informatrix"
Answer: Option D
Explanation:
Step 1: inti=0; The variable i is declared as in integer type and
initialized to '0'(zero).
Step 2: i++; Here variable i is increemented by 1. Hence i becomes
'1'(one).
Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is
satisfied and it enter into if block statements.
Step 4: printf("IndiaBIX"); It prints "IndiaBIX".
Step 5: exit(1); This exit statement terminates the program
execution.
Hence the output is "Informatrix".
PRINT(z);
return 0;
}
A. 2, 3, 4, B. 2, 2, 2,
C. 3, 3, 3, D. 4, 4, 4,
Option A
Explanation:
The macro PRINT(i) print("%d,", i) prints the given variable value in an
integer format.
Step 1: int x=2, y=3, z=4 The variable x, y, z are declared as an integer
type and initialized
to 2, 3, 4 respectively.
Step 2: PRINT(x) becomes printf("%d,",x). Hence it prints '2'.
Step 3: PRINT(y) becomes printf("%d,",y). Hence it prints '3'.
Step 4: PRINT(z) becomes printf("%d,",z). Hence it prints '4'.
14. What will be the output of the program (sample.c) given below if it is
executed from the
command line?
cmd> sample friday tuesday sunday
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%c", *++argv[2] );
return 0;
}
A. s B. f
C. u D. r
Answer: Option C
=> strcpy(str2, "Hello World") it copies the "Hello World" to the variable
str2.
16. What will be the output of the program if the array begins 1200 in
memory?
#include<stdio.h>
int main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u\n", arr, &arr[0], &arr);
return 0;
}
A. 1200, 1202, 1204 B. 1200, 1200, 1200
C. 1200, 1204, 1208 D. 1200, 1202, 1200
Answer: Option B
Explanation:
Step 1: int arr[]={2, 3, 4, 1, 6} The variable arr is declared as an
integer array and
initialized.
Step 2: printf("%u, %u, %u\n", arr, &arr[0], &arr) Here,
The base address of the array is 1200.
=> arr, &arr is pointing to the base address of the array arr.
=> &arr[0] is pointing to the address of the first element array arr. (ie.
base address)
Hence the output of the program is 1200, 1200, 1200
return 0;
}
A. 200 B. 30
C. 100 D. 500
Answer: Option B
Explanation:
Step 1: int k, num=30 here variable k and num are declared as an
integer type and variable
num is initialized to '30'.
Step 2: k = (num>5 ? (num <=10 ? 100 : 200): 500) This statement
does not affect the
output of the program. Because we are going to print the variable num in
the next statement.
So, we skip this statement.
Step 3: printf("%d\n", num) It prints the value of variable num '30'
Step 3: Hence the output of the program is '30'
20. What will be the output of the program, if a short int is 2 bytes wide?
#include<stdio.h>
int main()
{
short int i = 0;
for(i<=5 && i>=1;
++i; i>0)
printf("%u,", i);
return 0;
}
A. 1 ... 65535 B. Expression syntax error
C. No output D. 0, 1, 2, 3, 4, 5
Answer: Option A
Explanation:
for(i<=5 && i>=1
++i i>0) so expression i<=5 && i>=1
initializes for loop. expression
++i is the loop condition. expression i>0 is the increment expression.
21. If the size of pointer is 4 bytes then What will be the output of the
program ?
#include<stdio.h>
int main()
{
char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
printf("%d, %d", sizeof(str), strlen(str[0]));
return 0;
}
A. 22, 4 B. 25, 5
C. 24, 5 D. 20, 2
Answer: Option C
Explanation:
Step 1: char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"} The
variable str is
declared as an pointer to the array of 6 strings.
Step 2: printf("%d, %d", sizeof(str), strlen(str[0]))
sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints '24'
strlen(str[0])) becomes strlen(Frogs)). Hence it prints '5';
Hence the output of the program is 24, 5
/+*-
B.
*-/+
C.
+-/*
D.
/*+-
Ans Option D
Explanation:
Simply called as BODMAS (Bracket of Division, Multiplication, Addition and
Subtraction).
How Do I Remember ? BODMAS !
B - Brackets first
O - Orders (ie Powers and Square Roots, etc.)
DM - Division and Multiplication (left-to-right)
AS - Addition and Subtraction (left-to-right)
B.
C.
D.
65
Answer: Option A
Explanation:
Step 1: char p[] = "%d\n"; The variable p is declared as an array of
characters and initialized with string "%d".
Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'.
So array pbecomes "%c".
Step 3: printf(p, 65); becomes printf("%c", 65);
Therefore it prints the ASCII value of 65. The output is 'A'.
24. What will be the output of the program?
#include<stdio.h>
int get();
int main()
{
Answer: Option B
Explanation:
The while(j <= 255) loop will get executed 255 times. The size short int(2
byte wide)
does not affect the while() loop.
26. How many times the below loop will get executed?
#include<stdio.h>
main()
{
int i,j;
i = 10;
for (j=i==10 ; j<=10 ; j++)
{
printf("\n%d",j);
}
}
(A) 1
(B) 10
(C) 11
(D) Compilation Error
Answer : 10
Description : Expression i ==10 return 1 and j get initialized to 1.
a) h
b) i
c) e
d) y
Answer: b
int a=8,b=2,c;
c=a<<b;
printf("%d",c);
return 0;
}
a) 32
b) 16
c) 8
d) 4
Answer: a
Explanation: Write 8 in binary system(1000) and shift it towards left by 2
i.e. 100000 which is 32 in decimal system.
36.What is the output of this C code?
int main()
{
char c='8';
printf("%d",c);
return 0;
}
a) 56
b) 16
c) 8
d) 4
Answer: a
Explanation: 64-8
Answer: c
Explanation: main is not a keyword in C.
40. What is the output of the below c code?
#include<stdio.h>
int main()
{
char ch;
if(ch = printf(""))
printf("It matters\n");
else
printf("It doesn't matters\n");
return 0;
}
a) It matters
b) It doesnt matters
c) Run time error
d) Nothing
Answer: b
Explanation: printf returns the number of characters successfully written
on output.
Hence ch=0 and else statement executes.
47. Default storage class if not any is specified for a local variable, is auto
a) true
b) false
c) Depends on the standard
d) None of the mentioned
Answer: a
48.What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
printf("%f\n", sqrt(36.0));
return 0;
}
A. 6.0
B. 6
C.6.000000
D.Error: Prototype sqrt() not found.
Answer: Option C
Explanation:
printf("%f\n", sqrt(36.0)); It prints the square root of 36 in the float
format(i.e 6.000000).
Declaration Syntax: double sqrt(double x) calculates and return the
positive square root of the given number.
View Answer
Answer:c
50.What will be the output of program ?
#include<stdio.h>
int main( )
{
printf("nn /n/n nn/n");
return 0;
}
a.Nothing
b.nn /n/n nn
c.nn /n/n
d.Error
Show/Hide Answer
Answer = B
51. How many times will the following loop be executed?
ch = 'b';
while(ch >= 'a' && ch <= 'z')
A. 0 B. 25
C. 26 D. 1
View Answer & Explanation
Ans : B
52. Consider the following program fragment
switch(input)
{
case '1':
printf("One");
case '2':
printf("Two");
case '3':
printf(""Three");
default:
Printf("Default");
break;
}What will be printed when input is 2?
A. Two Three Default B. Two
C. Two Default D. Two Two Default
View Answer & Explanation
Ans : A
53. Consider the following 'C' program
#include<stdio.h>
int main()
{
int a=7, b=5;
switch(a = a % b)
{
case 1:
a = a - b;
case 2:
a = a + b;
case 3:
a = a * b;
case 4:
a = a / b;
default:
a = a;
}
return 0;
}On the execution of the above program what will be the value of a?
A. 7 B. 5
C. 2 D. None of the above
View Answer & Explanation
Ans : A
c.both a,b
d.int n{}={1,2,3,4,5,6}
ANS:a
57.What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
float n=1.54;
printf("%f, %f\n", ceil(n), floor(n));
return 0;
}
A. 2.000000, 1.000000
B. 1.500000, 1.500000
C. 1.550000, 2.000000
D. 1.000000, 2.000000
Answer: Option A
58. What function should be used to free the memory allocated by calloc() ?
A. dealloc();
B. malloc(variable_name, 0)
C. free();
D. memalloc(variable_name, 0)
Answer: Option C
59.. Point out the correct statement which correctly free the memory pointed to by 's'
and 'p' in the following program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct ex
{
int i;
float j;
char *s
};
struct ex *p;
p = (struct ex *)malloc(sizeof(struct ex));
p->s = (char*)malloc(20);
return 0;
}
A. free(p); , free(p->s);
B. free(p->s); , free(p);
C. free(p->s);
D. free(p);
Answer: Option B
60..Which statement will you add in the following program to work it correctly?
#include<stdio.h>
int main()
{
printf("%f\n", log(36.0));
return 0;
}
A. #include<conio.h>
B. #include<math.h>
C. #include<stdlib.h>
D. #include<dos.h>
Answer: Option B