C Mcq's
C Mcq's
C Mcq's
Ques. 1 Which is the character array used to accept command line arguments?
A) char argv
B) char* argv[]
C) char argv[]
D) char* argv
B)strcmp
C) strupr
D) strchr
Ques. 4 Which of the following does not require to include math.h header file?
A) pow()
B) rand()
C)sqrt()
D) sinh()
A) Expanding
B) Compiling
C) Linking
A) break
B) continue
C) goto
D) return
A) Memory address of the first element of the array Don’t remember the other
options.
Ques. 10 Another output based question which basically displayed the input string in
reverse pattern.
For example, ABRACADABRA was displayed as ARBADACARBA.
while(0 == 0) { }
C) It compares 0 with 0 and since they are equal it will exit the loop immediately
D) It has syntax error as the same number is being compared with itself.
#include <stdio.h>
void main()
{
int x = 97;
int y = sizeof(x++);
printf(“x is %d”, x);
}
a) x is 97
b) x is 98
c) x is 99
d) Run time error
#include <stdio.h>
void main()
int k = 5;
int *p = &k;
a) 5 5 5
b) 5 5 junk
c) 5 junk junk
Q2. Which of the following statements about stdout and stderr are true?
1) main() function should always be the first function present in a C program file
2) all the elements of an union share their memory location
3) A void pointer can hold address of any type and can be typecasted to any type
A) 2,3
B) 1,2
C) 1,2,3
D) 1,2,3,4
B) all the variable declared inside the function automatically will be assigned initial value
of zero
C) It should be called only within the same source code/program file.
while (0 == 0) { }
C) It compares 0 with 0 and since they are equal it will exit the loop immediately
D) It has syntax error as the same number is being compared with itself
Given the below statements about C programming language
1) main() function should always be the first function present in a C program file
3) A void pointer can hold address of any type and can be typcasted to any type
A) 2,3
B) 1,2
C) 1,2,3
D) 1,2,3,4
3. None of these
1. Linked Lists
2. Array of structures
3. All of these
4. Binary Tree
Q3. Strings are character arrays. The last index of it contains the null-terminated
character
1. \t
2. \1
3. \0
4. \n
1. String
2. Structure
3. Array
4. Files
Q5. What function should be used to free the memory allocated by calloc() ?
1. free();
2. malloc(variable_name, 0)
3. dealloc();
4. memalloc(variable_name, 0)
Q6. In the standard library of C programming language, which of the following header
file is designed for basic mathematical operations?
1. conio.h
2. stdio.h
3. math.h
4. dos.h
1. Pointer to integer
2. None of these
3. Pointer to pointer
4. Invalid declaration
1. (underscore)
2. – (hyphen)
3. | (pipeline)
4. * (asterisk)
1. Uppercase letters
2. None of these
#include <string.h>
#include <stdlib.h>
++param;
int main(){
strcpy(string, “hello_World”);
myfunc(&string);
myfunc(&string);
printf(“%s\n”, string);
return 0;
1. hello_World
2. ello_World
3. lo_World
4. llo_World
What is the output of this C code?
#include <stdio.h>
void main()
int k = 5;
int *p = &k;
a) 5 5 5
b) 5 5 junk
c) 5 junk junk
5. while declaring parameters for main, the second parameter argv should be declared
as
a) char argv[]
b) char argv
c) char ** argv[]
d) char * argv[]
11. which of the following is used locate the end of the file ?
Mine answers was feof()
12. A code will be given and you will be asked which header is missing??
In my question sqrt() was used and math.h was missing
a) 0
b) 1
c) 3
d) 5
8. What is recursion ?
a) looping
b) a function calls another function repeatedly
c) a fnction calls repeatedly
d) function calls itself repeatedly
a) Compilation error
b) Runtime error
c) 4
d) 1
B) all the variable declared inside the function automatically will be assigned
initial value of zero
C) It should be called only within the same source code / program file.
A) 2 or 4 —
B) 1 or 3
C) Garbage value
D) ASCII value of a
A) printf(“%ll\n”,fact(5));
B) printf(“%u\n”,fact(5));
C) printf(“%d\n”,fact(5));
D) printf(“%ld\n”,fact(5));
Ques. If a function’s return type is not explicitly defined then it’s default to ______ (In C).
A) int
B) float
C) void
D) Error
Which of the following statements about stdout and stderr are true?
2) What does argv and argc indicate in int main(int argc, char *argv[]) ?
a) MultiDimensional Array
b) Jagged Array
c) 2-Dimensional Array
d) Single Dimensional Array
a) argc
b) argc * 2
c) argc – 1
d) argc + 1
a)File Name
b)Program Designation
c)argument passed by user
d)Program Name
a)Array of pointers
b)pointer to a character array
c)Array of character pointers
d)Array of Strings
8) What will be the output of the following program if argument passed to command
lines are : prog 1 4 2
#include<stdio.h>
int main(int argc, char *argv[])
{
int j;
j = argv[1] + argv[2] – argv[3];
printf(“%d”, j);
return 0;
}
a)Error
b)3
c)Garbage Value
d)None of these
Ans–> Here, argv[1], argv[2] and argv[3] are of type String. So, we have to convert
String to integer before performing arithmetic operation.
a) Number of Arguments
b) Number of Arguments – 1
c) Number of Arguments + 2
d) Number of Arguments + 1
11) What will be output of the following program if argument passed to command lines
are : prog 1 4 2
#include<stdio.h>
int main(int argc, char *argv[])
{
while(argc–)
printf(“%s\n”,argv[argc]);
return 0;
}
a) 2 4 1
b) Garbage-value 2 4 1
c) Garbage-value 2 4 1 prog
d) Infinte Loop
12) What will be output of the following program if argument passed to command lines
are : demo one two three
#include<stdio.h>
int main(int argc, char *argv[])
{
printf(“%c\n”,**+argv);
return 0;
}
a) n
b) o
c) t
d) Compile Time Error
Ans–> Here, char * argv[ ] denotes Array of Pointers. So, argv[ ] holds the address of
the command line argument passed. ++argv denote the address of next location, which
holds the address of the 2nd argument.
*++argv denote the value stored at that address i.e. the address of the 1st character of
the 2nd argument and **++argv itself denote the character ‘o’ .
13) What will be output of the following program if argument passed to command lines
are : demo friday
#include<stdio.h>
int main(int argc, char *argv[])
{
printf(“%c”,*++argv[1]);
return 0;
}
a) r
b) f
c) i
d) d
Ans–>argv[1] can be wriiten as *(argv+1), (argv+1) denote the address of next location,
which holds the address of 2nd argument. Thus *(argv+1) or argv[1] denote the value
stored at that address i.e. denote the address of 1st character of the 2nd Argument.
++argv[1] denote the address of 2nd character of the 2nd Argument. So *++argv[1] itself
denote the character ‘r’ .
Questions – Variables and Data Types
Ans:c
Explanation:Variable name can’t start with a digit.
Ans:c
Ans:d
#include <stdio.h>
int main()
{
int main = 5;
printf(“%d”, main);
return 0;
}
a) compile-time error
b) run-time error
c) run without any error and prints 5
d) experience infinite looping
Ans:c
Explanation:A C program can have same function name and same variable name.
Ans: c
Explanation:volatile is C keyword
8. The format identifier ‘%i’ is also used for _____ data type?
a) char
b) double
c) float
d) int
Ans:d
Explanation:Both %d and %i can be used as a format identifier for int data type.
Ans:c
#include <stdio.h>
int main()
{
signed char chr;
chr = 128;
printf(“%d\n”, chr);
return 0;
}
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
Ans:b
Explanation:signed char will be a negative number.
Ans:c
Ans:b
Explanation:Since the size of the structure depends on its fields, it has a variable size.
#include <stdio.h>
int main()
{
float x = ‘a’;
printf(“%f”, x);
return 0;
}
a) 97.000000
b) run time error
c) a.0000000
d) a
Ans:a
Explanation:Since the ASCII value of a is 97, the same is assigned to the float variable and
printed.