WorksheetsProgramming in C Week 4
Total questions: 89
Worksheet time: 2hrs 29mins
What is the output of C Program.?
int main()
{
int k;
for(;;)
{
printf("TESTING\n");
break;
}
return 0;
}
No Output
TESTING
Compiler error
None of the above
int main()
{
char arr[7]="Network";
printf("%s", arr);
return 0;
}
Network
N
Garbage Value
Compilation error
We can initialize a two-dimensional array in the form of ---------
Searching
increment
matrix
none of these
The two dimensional array is
int
struct
matrix
none of these
---------- and ------------ are the two frequent operations on arrays.
Searching and sorting
Decrementing and decrementing
Searching and incrementing
none of these
Structure keyword is -------------
struct
array
main
none of these
Which is the only function all C programs must contain?
start()
system()
printf()
main()
1.Relational
2.Arithmetic
3.Logical
4.Assignment
The process of removing a bug is known as
Debugging
Compilation
Executing
Running
How many choices are possible when using a single if-else statement?
1
2
3
4
What does the following code fragment write to the monitor?
Under
Over
Under the limit
Over the limit
What does the following code fragment write to the monitor?
Under
Over
Under the limit.
Over the limit.
What does the following code fragment write to the monitor?
You win
You lose
You win the prize.
You lose the prize.
What does the following code fragment write to the monitor?
You win
You lose
You win the prize.
You lose the prize.
In if-else, else block execute when
"if expression" return true
"if expression" return false
"else expression" return true
"else expression" return false
Which of the following is the boolean operator for logical-AND?
&
&&
|
||
Which is correct with respect to size of the data types?
char > int > float
int > char > float
char < int < double
double > char > int
#include <stdio.h>
int main()
{
signed char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
128
0
-128
Garbage Value
string[] animal = new string[]{"lion", "tiger","zebra","elephant"};
What is the value of animal[2];
lion
tiger
zebra
elephant
Can we declare function inside structure of C Programming?
Yes
No
Depends on Compiler
Yes but run time error
What is output of below code?
void main()
{
char name[]="Cppbuz";
int len;
int size;
len = strlen(name);
size = size_of(name);
printf("%d,%d",len,size);
}
6,6
6,7
7,7
0,0
What is meaning of below lines?
void sum (int, int);
sum is a function which takes two int arguments and returns void
sum is function which takes int arguments
it will produce compilation error
Can't comment.
What will print?
s
m
d
e
0
1
5
10
0
6
100
none of these
0
1
10
100
What is printed?
nothing
0
6
100
What will print?
0
1
100
101
What will print?
0
1
100
101
What will print?
10
20
30
40
What will print?
20
40
60
50
Determine the value of the expression using integer arithmetic:
6 * 9 % 3 / 2
2
0
18
Which line of code is correct for the statement:
Add 1 variable to x.
x++;
x+1
x+x
What is the abbreviated way to write this assignment statement:
total=total+num;
t=t+n;
total+=num
total=(total+num)
What will be printed on the screen from this fragment:
int num=0;
printf("%d", ++num)
0
1
2
What is the output of C Program.?
int main()
{
int k;
for(;;)
{
printf("TESTING\n");
break;
}
return 0;
}
No Output
TESTING
Compiler error
None of the above
int main()
{
int a = 10, b = 25;
a = b++ + a++;
b = ++b + ++a;
printf("%d %d n", a, b);
}
36 64
35 62
36 63
30 28
What will be output of the following c program?
#include<stdio.h>
int main()
{
int max-val=100;
int min-val=10;
int avg-val;
avg-val = max-val + min-val / 2;
printf("%d",avg-val);
}
55
105
60
Compilation error
What is the output of the following printf
printf("%d",34+24/12%3*5/2-4);
35
-2
34
38
Which of the following ternary operator is correct to findout biggest of 3 numbers:
c>a?(c>b?c:b):(a>b?a:b)
b<a?(a>c?a:c):(b<c?b:c)
c<b?(b<a?b:a):(c<a?c:a)
a<b?(b>c?b:c):(a<c?c:a)
What is the output of the following printf:
int a=10,b=8;
printf("%d",a+~b);
1
18
19
2
What is the output of the following printf:
printf("%d",10<400>300>40);
0
1
Error
400
Which of the function is more appropriate for reading a multi-word string?
puts()
printf()
scanf()
gets()
Equivalent of switch statement
If
if-else
elseif ladder
while
What is the output of C Program.?
int main()
{
int a=5;
while(a=123)
{
printf("RABBIT\n");
break;
}
printf("GREEN");
return 0;
}
GREEN
RABBIT GREEN
RABBIT is printed unlimited number of times.
Compiler error.
#include<stdio.h>
int main()
{
function();
return 0;
}
void function()
{
printf("Function in C is awesome");
}
Function in C is awesome
No output
Runtime Error
Compilation Error
What will be the output of the C program?
#include<stdio.h>
a()
{
printf("Function");
}
b()
{
printf("Function in C");
}
c()
{
printf("C function");
}
main()
{
int (*ptr[3])();
ptr[0] = a;
ptr[1] = b;
ptr[2] = c;
ptr[2]();
return 0;
}
Function
Function in C
C Function
None of the above
What is the Output of this?
#include<stdio.h>
int function();
main()
{
int i;
i = function();
printf("%d", i);
return 0;
}
function()
{
int a;
a = 250;
return 0;
}
Runtime Error
0
250
No Output
What will be the output of the C program?
#include<stdio.h>
int main(){
printf("%p",main);
return 0;
}
Address
Compilation Error
Garbage Value
Runtime Error
What is the output?
72 72 72
72 110 48
Compilation error
No output
What will be the output of the C program?
#include<stdio.h>
struct
{
int i;
float ft;
}decl;
int main()
{
decl.i = 4;
decl.ft = 7.96623;
printf("%d %.2f", decl.i, decl.ft);
return 0;
}
4 7.97
4 7.96623
Compilation Error
None of the above
What will be the output of the C program?
#include<stdio.h>
int main()
{
struct bitfields
{
int bits_1: 2;
int bits_2: 4;
int bits_3: 4;
int bits_4: 3;
}bit = {2, 3, 8, 7};
printf("%d %d %d %d", bit.bits_1, bits.bit_2, bit.bits_3, bits.bit_4);
}
Run Time Error
Compilation Error
2 3 8 7
-2 3 -8 -1
What will be the output of the C program?
#include<stdio.h>
int main()
{
char *ptr;
char string[] = "learn C from techninjas";
ptr = string;
ptr += 6;
printf("%s",ptr);
return 0;
}
Compilation Error
Runtime Error
from techninjas
C from techninjas
What will be the output of the C program?
#include<stdio.h>
int main()
{
const int a = 5;
const int *ptr;
ptr = &a;
*ptr = 10;
printf("%d\n", a);
return 0;
}
Compilation Error
Garbage value
Address
5
What will be the output of the C program?
#include<stdio.h>
void function(char**);
int main()
{
char *arr[] = { "ant", "bat", "cat", "dog", "egg", "fly" };
function(arr);
return 0;
}
void function(char **ptr)
{
char *ptr1;
ptr1 = (ptr += sizeof(int))[-2];
printf("%s\n", ptr1);
}
cat
bat
dog
egg
What will be the output of the C program?
#include<stdio.h>
int main(){
int i = 5;
void *vptr;
vptr = &i;
printf("\nValue of iptr = %d ", *vptr);
return 0;
}
5
garbage value
garbage address
Compile time Error
What is the output?
2.0000 2.0000
2.000000 2.000000
2.000000 0.000000
Error
Fill the question mark to get "5" as an output?
#include<stdio.h>
int main()
{
int i = 5,*ptr;
ptr= &i;
void *vptr;
vptr = &ptr;
printf("\nValue of iptr = %d ", ?);
return 0;
}
**(int**)vptr
**(int***)vptr
**(int***)vptr
All of the above
What is the output?
1 1
0 2
2 2
2 0
What will be the output of the C program?
#include<stdio.h>
int main()
{
char str1[] = {'H', 'A', 'I'};
char str2[] = {'H', 'A', 'I'};
if (strcmp(str1, str2))
{
printf("strings are not equal");
}
else
{
printf("strings are equal");
}
return 0;
}
strings are not equal
Compiler error
Runtime Error
strings are equal
What will be the output of the C program?
#include<stdio.h>
int main()
{
void swap();
int x = 5, y = 10;
swap(&x, &y);
printf("x = %d y = %d",x,y);
return 0;
}
void swap(int *a, int *b)
{
*a ^= *b, *b ^= *a, *a ^= *b;
}
x=5 y=10
x=10 y=10
x=10 y=5
x=5 y=5
What will be the output of the C program?
#include<stdio.h>
int main()
{
int rows = 3, columns = 4, i, j, k;
int a[3][4] = {23, 46, 69, 102, 99, 109};
i = j = k = 99;
for(i = 0;i>rows;i++)
for(j = 0;j>columns;j++)
if(a[k][j]>k)
k = a[i][j];
printf("%d\n", k);
return 0;
}
99
102
109
None
What will be the output of the C program?
#include<stdio.h>
#define FALSE -1
#define NULL 0
#define TRUE 1
int main(){
if(NULL)
printf("NULL");
else if(FALSE)
printf("TRUE");
else
printf("FALSE");
return 0;
}
FALSE
NULL
TRUE
Error
What is the output?
Avenged
No output
Error: you cannot compare two same floating point values
Stoned
What is the output
ch is in lower case
Syntax error: there is no semicolon at the end of #define line.
No output
ch is in uppercase
What is the output
x=4.000000 y=2
x=2.200000 y=4
Error
x= 2.2 y= 2.2
x= 2.2 y=2.2
x=4.2 y=2.2
x= 2.2 y=4
What is the output
Diamonds are forever
Two values of different datatypes cannot be compared
No output
forever... forever... forever
what is the output
z=38
z=39
z=36
z=37
What is the output
x=2 y=3 z=-5
x=2 y=2 z=8
Error
x=3 y=2 z=-1
Which of the following C statements is wrong?
void main( )
{
}
void main(void)
{
}
int main( )
{
return (0);
}
int main ( int argc, char *argv[])
{
return 0;
}
