0% found this document useful (0 votes)
23 views6 pages

CPViva

The document contains a series of multiple-choice questions related to the C programming language, covering topics such as variable naming, iteration statements, preprocessor directives, and function declarations. Each question is followed by its correct answer. The questions test knowledge on syntax, functions, and file handling in C.

Uploaded by

Anandhu Krishnan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

CPViva

The document contains a series of multiple-choice questions related to the C programming language, covering topics such as variable naming, iteration statements, preprocessor directives, and function declarations. Each question is followed by its correct answer. The questions test knowledge on syntax, functions, and file handling in C.

Uploaded by

Anandhu Krishnan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1. Which of the following is not a valid C variable name?

a) int number;

b) float rate;

c) int variable_count;

d) int $main;

Ans: int $main;


2. What is an example of iteration statements in C?
a) for
b) while
c) do-while
d) all of the mentioned
Ans:d
3. What is #include <stdio.h>?
a) Preprocessor directive
b) Inclusion directive
c) File inclusion directive
d) None of the mentioned
Ans:a
4. scanf() is a predefined function in______header file.
a) stdlib. h
b) ctype. h
c) stdio. h
d) stdarg. H
Ans: c
5. What will be the final value of x in the following C code?

1. #include <stdio.h>
2. void main()
3. {
4. int x = 5 * 9 / 3 + 9;
5. }
a) 3.75
b) Depends on compiler
c) 24
d) 3

Ans :c
6. How many times i value is checked in the following C program?

#include <stdio.h>
int main()
{
int i = 0;
while (i < 3)
i++;
printf("In while loop\n");
return 0;
}

a) 2
b) 3
c) 4
d) 1
Ans:c
7. What will be the output of the following C code? (Assuming that we have entered
the value 1 in the standard input)
#include <stdio.h>
void main()
{
int ch;
printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\t");
default:
printf("2\t");
}
}
a) 1
b) 2
c) 1 2
d) Run time error
Ans: c
8. Size of an array can be evaluated by __________
(Assuming array declaration int a[10];)
a) sizeof(a);
b) sizeof(*a);
c) sizeof(a[10]);
d) 10 * sizeof(a);
Ans:a

9. Which string function will you choose to join two words?


a) strcpy()
b) strcat()
c) strncon()
d) strjoin()
Ans:b
10. What is the Format specifier used to print a String or Character array in C Printf or
Scanf function?
a) %c
b) %C
c) %s
d) %w
Ans:c
11. How do you declare a 2 dimensional integer array with 3 rows and 4 columns?
a. int arr[3,4];
b. int arr[3][4];
c. int[3,4] arr;
d. int[4][3] arr;
Ans: b
12. What will be printed after the execution of following code?
void main()
{
int arr[10]={1,2,3,5};
printf(“%d”,arr[5]);
}
a. 5
b. 6
c. 0
d. None of the above
Ans:c
13. What is the result of the expression strlen(“Hello”) in C?
a. 5
b. 6
c. 4
d. 10
Ans:5
Module 3
14. What is the problem in the following C declarations?

int func(int);
double func(int);
int func(float);
a) A function with same name cannot have different signatures
b) A function with same name cannot have different return types
c) A function with same name cannot have different number of parameters
d) All of the mentioned

Ans:d
15. Which of the following is a correct format for declaration of function?
a) return-type function-name(argument type);
b) return-type function-name(argument type) { }
c) return-type (argument type)function-name;
d) all of the mentioned
Ans:a
16. The value obtained in the function is given back to main by using ________
keyword.
a) return
b) static
c) new
d) volatile
Ans:return
17. Which operator connects the structure name to its member name?
a) –
b) <-
c) .
d) Both <- and .
Ans:c
18. The correct syntax to access the member of the ith structure in the array of
structures is?
Assuming: struct temp
{
int b;
} s[50];
a) s.b.[i];
b) s.[i].b;
c) s.b[i];
d) s[i].b;
Ans:d
19. The size of a union is determined by the size of the __________
a) First member in the union
b) Last member in the union
c) Biggest member in the union
d) Sum of the sizes of all members
Ans: c
Module 4
20. Which is an indirection operator among the following?
a) &
b) *
c) ->
d) .
Ans : b
21. Which of the following are correct file opening modes in C?
a. r
b. rb
c. w
d. All of the above
Ans: d
22. A mode which is used to open an existing file for both reading and writing ______
a) w
b) w+
c) r+
d) a+
Ans:c
23. Select a function which is used to write a string to a file ______
a) puts()
b) putc()
c) fputs()
d) fgets()
Ans:c
24. What is meant by ‘a’ in the following C operation?

fp = fopen("Random.txt", "a");
a) Attach
b) Append
c) Apprehend
d) Add

Ans: b

You might also like