0% found this document useful (0 votes)
19 views125 pages

PPS Question Bank With Unitwise MCQ

The document contains a series of multiple-choice questions (MCQs) related to programming and problem-solving, specifically focusing on the C programming language. Topics covered include the history of C, data types, variable declarations, control structures, and the role of compilers and assemblers. Each question is tagged with learning outcomes (CLO) and program learning outcomes (PLO) for educational assessment purposes.

Uploaded by

billaraman123456
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)
19 views125 pages

PPS Question Bank With Unitwise MCQ

The document contains a series of multiple-choice questions (MCQs) related to programming and problem-solving, specifically focusing on the C programming language. Topics covered include the history of C, data types, variable declarations, control structures, and the role of compilers and assemblers. Each question is tagged with learning outcomes (CLO) and program learning outcomes (PLO) for educational assessment purposes.

Uploaded by

billaraman123456
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/ 125

PROGRAMMING FOR PROBLEM SOLVING

Unit 1

Multiple Choice questions MCQ

1. Who is father of C Language? [CLO 1] [PLO1]


A. Bjarne Stroustrup B. Dennis Ritchie
C. James A. Gosling D. Dr. E.F. Codd
2. C Language developed at _____? [CLO 1] [PLO 1]
A. AT & T's Bell Laboratories of USA in 1972
B. AT & T's Bell Laboratories of USA in 1970
C. Sun Microsystems in 1973
D. Cambridge University in 1972

3. For 16-bit compiler allowable range for integer constants is ______ ? [CLO 1] [PLO 2]
A. -3.4e38 to 3.4e38
B. -32767 to 32768
C. -32768 to 32767
D. -32668 to 32667
4. C programs are converted into machine language with the help of [CLO 1] [PLO 1]
A. An Editor
B. A compiler
C. An operating system
D. None of the above
5. A C variable cannot start with [CLO 1] [PLO 1]
A. An alphabet
B. A number
C. A special symbol other than underscore
D. both (b) and (c)

6. Which of the following is allowed in a C Arithmetic Instruction? [CLO 1] [PLO 1]


A. []
B. {}
C. ()
D. None of the above
7. Which of the following shows the correct hierarchy of arithmetic
operations in C [CLO 1] [PLO 2]
A. / + * -
B. * -/ +
C. + - / *
D. * / + -

8. Program which is written originally by the programmer is classified as [CLO 1] [PLO 1]

A. object code
B. machine code
C. source program
D. interactive programs
9. Data types are differed on the basis of [CLO 1] [PLO 1]

A. the way of storage


B. the type of operations
C. the type of operators used
D. both a and b

10. Loop statement which is repeated for some given number of times is classified as [CLO 1]

A. FOR loop
B. GO loop
C. REPEAT loop
D. GO REPEAT loop

11. Type of statement written in sequence and is repeated until the specific condition met is
classified as [CLO 1] [PLO 1]

A. format
B. loop
C. case
D. condition

12. Size of an array is declared by [CLO 1] [PLO 1]

A. programmer
B. program users
C. software
D. declared automatically

13. Programming language 'FORTRAN' stands for [CLO 1] [PLO 1]

A. formula translator
B. formula translation
C. free translator
D. free translation

14. Functions that are used in the programs and are defined by the programmers are called
[CLO 1] [PLO 2]

A. program layout
B. program procedure
C. built-in functions
D. user-defined function
15. An assembler translates [CLO 1] [PLO 1]

A. machine code into assembly code


B. assembly code into machine code
C. processing time into manual time
D. routine into subroutine

16. Name given by a programmer to any particular data is classified as [CLO 1] [PLO 1]

A. identifier
B. identification
C. exponent
D. mantissa

17.When variable used in program is whole number, the variable is stored as [CLO 1] [PLO 2]

A. fixed string
B. integers
C. negative whole numbers
D. positive whole numbers

18. In programming, programmers use comments to [CLO 1] [PLO 1]

A. highlight program modules


B. explain module functions
C. explain used variables
D. all of above

19. Variable which uses the same name in whole program and in its all routines thus best classified
as [CLO 1] [PLO 2]

A. middle variable
B. default variable
C. local variable
D. global variable

20. Statement which is used to make choice between two options and only option is to be performed
is written as [CLO 1] [PLO 2]

A. if statement
B. if else statement
C. then else statement
D. else one statement
21. The__________ statement is used to transfer the control to the end of statement block in a loop:

a. Continue [CLO 1] [PLO 2]


b. Break
c. Switch
d. Goto
22. Which of the following is not a valid variable name declaration? [CLO 1] [PLO 2]
a) int _a3;
b) int a_3;
c) int 3_a;
d) int _3a

23. All keywords in C are in [CLO 1] [PLO 2]


a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None of the mentioned

24. Which of the following is true for variable names in C? [CLO 1] [PLO 2]
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length

25. The format identifier ‘%i’ is also used for _____ data type? [CLO 1] [PLO 2]
a) char
b) int
c) float
d) double

26. Which of the following is a User-defined data type? [CLO 1] [PLO 3]


a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) struct {char name[10], int age};
d) all of the mentioned

27. What is the output of this C code? [CLO 1] [PLO 3]

1. #include <stdio.h>
2. int main()
3. {
4. signed char chr;
5. chr = 128;
6. printf("%d\n", chr);
7. return 0;
8. }
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned

28. What is the output of this C code? [CLO 1] PLO 3]


1. #include <stdio.h>
2. int main()
3. {
4. j = 10;
5. printf("%d\n", j++);
6. return 0;
7. }

a) 10 b) 11
c) Compile time error d) 0
Explanation : j is not belongs to any data type

29. The following code ‘for( ; ; )’ represents an infinite loop.

It can be terminated by. [CLO 1] [PLO 3]


a) break b) exit(0)
c) abort() d) all of the mentioned

30. The keyword ‘break’ cannot be simply used within: [CLO 1] [PLO 3]
a) do-while b) if-else
c) for d) while

31. Which keyword is used to come out of a loop only for that iteration? [CLO 1] [PLO 3]
a) break b) continue
c) return d) none of the mentioned
32. The first step in problem solving is --------------- [CLO 1] [PLO 2]
a) Understand the problem c)Identify the problem
b) Developing algorithm/Flowchart d)Listing the possible outcome
33. The solutions which has series of actions to solve a problem are called ------ [CLO 1] [PLO 2]
a) Heuristic solutions
b) Algorithmic solutions
34. The solution can be reached by completing the actions in steps. These steps are called [CLO 1]
[PLO 2]
a) Sequence c)Algorithm
b) Flowchart d)Steps
35. Solutions that cannot be reached through a direct set of steps are called --------- [CLO 1][PLO 2]
a)Algorithmic solutions b) Heuristic solutions
36. ----------- means the outcome or the completed computer-assisted answer. [CLO 1][PLO 1]
a) Solution b) Result c) Program
37. The field of computer that deals with the problem of heuristic solution is called-----[CLO 1]
[PLO1]
a) Artificial Intelligence
b) Expert System c) Computer Management

38. ----------------- means the set of instructions that make up the solution after they have been coded
into a programming language. [CLO 1] [PLO1]
a) solution b) result c) program d) error

39. ---------------- are organized facts. [CLO 1] [PLO1]


a) Data b) Information

40. A language applied for wide range of application is called as ______language[CLO 1][PLO 2]

a. Special purpose c)General purpose


b. Individual purpose d)Scientific purpose

41. Compiler converts the source code into ______ [CLO 1][PLO 4]
a. C code b. Byte code c. Object code d. Executable code

42. ___________ converts source code to machine language one line at a time. [CLO 1][PLO 4]
a. Compiler b. Interpreter c. Assembler d.CPU

43. The program that converts high level language to a machine language is called __________
[CLO 1] [PLO 1]
a. Interpreter b. Linker c. Compiler d. Loader

44. ‘#’ symbol is known to be ______ [PLO 2] [CLO 1]


a. Linker b.Compiler c. Assembler d.Preprocessor directive

45. A _______ is a notational system for describing computations in both machine and human
readable form [PLO 1] [CLO 1]
a. Programming language c.Machine language
b. High-level language d.Assembly language

46. ----------------- program converts assembly language into machine language [PLO 2] [CLO 1]
a. compiler b. interpreter c. assembler d. preprocessor directive

47. which symbol is been used for processing in flowchart? Ans: a [CLO 1] [PLO 3]

a) b) c) d)

48. which symbol is been used for input/output in flowchart? Ans: c [PLO 3] [CLO 1]
a) b) c) d)

49. which symbol is been used for decision making in flowchart? Ans: d [PLO 3] [CLO 1]

a) b) c) d)

50. which is used as start/stop symbol in flowchart? Ans:b [PLO 3] [CLO 1]

a) b) c) d)

51. ------------ is a distinguishing characteristic of human excellence in every area of behavior


[CLO 1] [PLO 1]
a) creativity b) thinking c) visualization d) problem solving

52. .What is the value of x in this C code? [PLO 2] [CLO 1]


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

53.A character variable can store how many characters at a time? [PLO 2][CLO 1]
(a) 1 character
(b)8 characters
(c)255 character

54.Which of the following is the correct way of writing comments? [PLO 2] [CLO 1]
(a)*/comments/*
(b)/*comment*/
(c)**comment** (
d){comment}

55. C programming language is [PLO 1] [CLO 1]


(a)object oriented programming language (b)Procedure oriented programming language
(c)function oriented programming language (d)None of the above

56.The memory space taken for a char type data is [PLO 2] [CLO 1]
(a)2 bytes
(b)4 bytes
(c)8 bytes
(d)1bytes

57 .The memory space taken for a int type data is [PLO 2] [CLO 1]
(a) 2 bytes
(b) 4 bytes
(c) 8 bytes
(d)10bytes

58.The memory space taken for a float type data is [PLO 2] [CLO 1]
(a) 2 bytes
(b) 4 bytes
(c) 8 bytes
(d)10bytes

59. What is the only function all programs must contain ? [PLO 2] [CLO 1]
(a)start()
(b)system()
(c)main()
(d)program

60.For 16-bit compiler allowable range for integer constants is ________? [PLO 2] [CLO 1]
(a) -3.4e38 to 3.4e38
(b) -32767 to 32768
(c) -32668 to 32667
(d) -32768 to 32767

61.Every statement in C program is to be terminated by a__________ [PLO 2] [CLO 1]


(a)dot(.)
(b)semi-colon(;)
(c)colon(:)
(d)Question mark(?)

62 The escape sequence „\b‟ is a [PLO 2] [CLO 1]


(a)back space
(b)next line
(c)tab
(d)none of the above

63.The memory space taken for a long int type data is [PLO 2] [CLO 1]
(a) 2 bytes
(b) 4 bytes
(c) 8 bytes
(d)10bytes

64. which of the following will not valid expressions in C? [PLO2] [CLO 1]
(a) a=2+(b=5);
(b) a=11%3
(c) a=b=c=5
(d) b+5=2
65. The --------------------- operator is true only when both the operands are true. [PLO 2][CLO 1]
a) &&
b) b) ||
c) c)!
d) d) ?:

66. The ---------------------- statement when executed in a switch statement causes immediate exit
from the structure. [CLO 1] [PLO 2]

a)goto
b) default
c) break
d) switch

66. The ternary conditional expression using the operator?: could be easily coded using ----------------
- statement [CLO 1][PLO 2]
a)Nested if b) if-else
c) if d) for

4 Marks :

Unit-1 CLO-1

1. Comment “C is mid level language”? [CLO-1][PLO 1]


2. What is problem solving? [CLO-1][PLO 1]
3. What are the six steps of problem solving? [CLO-1][PLO 1]
4. Discuss about how the problems can be solved with computers? [CLO-1][PLO 1]
5. What is a program? [CLO-1][PLO 2]
6. Why is problem analysis important? [CLO-1][PLO 2]
7. What are the tools of problem solving available? [CLO-1][PLO 2]
8. How do problem-solving tools help in leading to a solution? [CLO-1][PLO 2]
9. Why it is important to test a solution before coding it? [CLO-1][PLO 2]
10.What is an algorithm? Give the characteristics of the algorithm. [CLO-1][PLO 2]
11.What is a flowchart? Give the symbols/shapes used in the flowchart.
[CLO-1][PLO 3]
12.Define pseudocode and give its importance with an example. [CLO-1][PLO 2]
13.Discuss the difficulties with problem solving in detail. [CLO-1][PLO 2]
14.State the use of %d and %f .Write a printf statement in C using the above
mentioned symbols? [CLO-1][PLO 4]
15.What is main difference between variable and constant? [CLO-1][PLO 3]
16.Explain bitwise left shift operator? [CLO-1][PLO 4]
17.Explain primary data types used in C? [CLO-1][PLO 3]
18.Difference between formatted & unformatted statement ? [CLO-1][PLO 3]
19.What is mean by storage class of variable? [CLO-1][PLO 3]
20.Explain with example ++i and i++. [CLO-1][PLO 4]
21. Refer all Elab programs. [CLO-1][PLO 3] [PLO 2][PLO 4]

12 Marks:

1) Explain the evolution of programming languages. [CLO-1][PLO 1]


2) Explain the various steps involved in problem solving with diagram. [CLO-1][PLO 1]
3) Draw the flowchart and write the algorithm and c code to find the sum and to reverse the
digits of given five digit number. [CLO-1][PLO 1] [PLO2]
4) Write an algorithm and draw a flow chart to find the factorial and Fibonacci series of given
number. [CLO-1][PLO 2] [PLO 3]

5) Write a note on Algorithm, Flow chart and Pseudocode. [CLO-1][PLO 3] [PLO 2]

6) Explain the scope, lifetime of variable in C with example. [CLO-1][PLO 2][PLO3]

7) Write down the algorithm to find the largest number among three given numbers and
outline the steps in the algorithm with the inputs 5, 17, 3. [CLO-1][PLO 2][PLO3]
8) Draw flowchart to compute the salary of an employee in a company. Assume that there are
two types of employees in the company daily wages and regular. Salary is calculated as
number of hours worked* wages per hour for daily wagers and basic pay +(% of DA * basic
pay)/100 + HRA + medical allowance for regular employees. Sketch the flow of your design
for a regular employee with basic pay = 5000, % of DA = 75 % and HRA = 500. (8)
[CLO-1][PLO 2][PLO3][PLO4]

9) Explain in details about operators with an example [CLO-1][PLO 1] [PLO 2][PLO3]

10) Refer all elab Programs [CLO-1][PLO 3] [PLO 2][PLO 4]


UNIT - II
PART A

1. The --------------------- operator is true only when both the operands are true.
e) && b) || c)! d) ?:
Answer: a
2. The ---------------------- statement when executed in a switch statement causes immediate exit
from the structure.
a)goto b) default c) break d) switch
Answer: c
3. The ternary conditional expression using the operator?: could be easily coded using ----------------
- statement
a)Nested if b) if-else c) if d) for
Answer: b
4. What will be the output when the following segment is executed?
Char ch=’a’;
Switch(ch)
{
case ‘a’:
Printf(“A”);
case ’b’:
Printf(“B”);
Default:
printf(“C”);
}

a)A b)B c)C d) a


Answer: a
5. What will be the output of the following segment when executed?
int x=10, y=20;
if((x<y)||(x+5)>10)
printf(%d”,x);
else
printf(%d”,y);

a)10 b) 20 c) 15 d)5

Answer: a
6. The ----------------------- statement is used to skip a part of the statements in a loop.
a) Continue b) break c) goto d)switch
Answer: a
7. A for loop with no test condition is known as --------------- loop
a) Infinite b) time delay c) for d) Incrementing
Answer: a
8. The sentinel –controlled loop is also known as -----------------------loop
a) Indefinite repetition loop c) time delay
b) Definite repetition loop d) infinite
Answer: a
9. In an exit controlled loop the body of the loop is always executed minimum number of ------------
a) 1 time b)2 times c) 3 times d)n times
Answer:a
10. The while is an --------------------- loop statement.
a) Entry-controlled b)exit-controlled c)indefinite repetition
d)definite repetition
Answer: a
11. The ------------------specification is used to read or print integers
a)h b)l c)L d)c
Answer: a
12. To print the data left-justified, must use -------------- in the field specification
a) - b) + c) / d) *
Answer: a
13. By default, the real numbers are printed with a precision of --------------- decimal.
a)6 b)2 c)4 d)0
Answer:a
14. The expression !(x!=y) can be replaced by the expression--------------------
a) x!=y b) x==y c)x=!y d)!x=!y
Answer:c
15. In a counter controlled loop, variable known as -----------------is used to count the loop
operations.
a) Counter b)sentinel c)i d)n
Answer: a

16. Which of the following special symbol allowed in a variable name?


(a) * (asterisk) (b)| (pipeline) (c) - (hyphen) (d) _ (underscore)

17 . Which of the following are invalid variable names?


a) Minimum b)n$ c) Integer d) float

18. int a=10;


++a;
a++;
Printf(“%d”,a);
a)10 b) 11 c)12 d) 13

19. int a=11;


a=a%2;
a=a/2;
The value of a is,
a) 1, 1 b) 5,1 c) 1,5 d)5
20. Which of the following is not logical operator?
A. &

B. &&

C. ||

D. !
21 Which of the following cannot be checked in a switch-case statement?
A. Character

B. Integer

C. Float

D. enum
22. What is the output of this C code?

int main()
{
int a = 0, i = 0, b;
for (i = 0;i < 5; i++)
{
a++;
continue;
}
}

A. 2 B. 3
C. 4 D. 5

23. What is the output of this C code?

void main()
{
int i = 0, j = 0;
for (i = 0;i < 5; i++)
{
for (j = 0;j < 4; j++)
{
if (i > 1)
break;
}
printf("Hi \n");
}
}
A. Hi is printed 5 times B. Hi is printed 9 times
C. Hi is printed 7 times D. Hi is printed 4 times
24. What is the output of this C code?
void main()
{
int i = 0;
int j = 0;
for (i = 0;i < 5; i++)
{
for (j = 0;j < 4; j++)
{
if (i > 1)
continue;
printf("Hi \n");
}
}
}
A. Hi is printed 9 times B. Hi is printed 8 times
C. Hi is printed 7 times D. Hi is printed 6 times

25. What is the output of this C code?

void main()
{
int i = 0;
for (i = 0;i < 5; i++)
if (i < 4)
{
printf("Hello");
break;
}
}
A. Hello is printed 5 times B. Hello is printed 4 times
C. Hello D. Hello is printed 3 times

27. What is the output of this C code?

int main()
{
int i = 0;
char c = 'a';
while (i < 2){
i++;
switch (c) {
case 'a':
printf("%c ", c);
break;
break;
}
}
printf("after loop\n");
}
A. a after loop B. a a after loop
C. after loop D. None of the mentioned
28. int main()
{
printf("before continue ");
continue;
printf("after continue\n");
}

A. Before continue after continue B. Before continue

C. after continue D. Compile time error

29. What is the output of the code given below?

int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
}

A. 1 4 B. Compilation error

C. 1 2 4 D. 1 3 4

30. What is the output of code given below?


int main()
{
printf("%d ", 1);
l1:l2:
printf("%d ", 2);
printf("%d\n", 3);
}
A. Compilation error B. 1 2 3
C. 1 2 D. 1 3
31. What will happen if in a C program you assign a value to an array element whose subscript
exceeds the size of array?
A. The element will be set to 0.
B. The compiler would report an error.
C. The program may crash if some important data gets overwritten.
D. The array size would appropriately grow.
32 .In C, if you pass an array as an argument to a function, what actually gets passed?
A. Value of elements in array
B. First element of the array
C. Base address of the array
D. Address of the last element of array

33. Result of a logical or relational expression in C is?


A. True or False
B. 0 or 1
C. 0 if expression is false and any positive number if expression is true
D. None of the mentioned
34. What will be the value of d in the following program?

int main()
{
int a = 10, b = 5, c = 5;
int d;
d = b + c == a;
printf("%d", d);
}

A. Syntax error

B. 1

C. 5

D. 10

35. What is the output of this C code?

int main()
{
int a = 10, b = 5, c = 3;
b != !a;
c = !!a;
printf("%d\t%d", b, c);
}
A. 5 1
B. 0 3
C. 5 3
D. 1 1

36. What is meaning of following declaration ?


int arr[20];

a) Array of size 20 that can have integer address

b) None of the above

c) Integer array of size 20

d) Array of sixe 20

37. In C Programming, If we need to store word "INDIA" then syntax is as below –

a) char name[6]={‘I’,’N’,’D’,’I’,’A’,’\0’}

b) char name[6]={“I”,”N”,”D”,”I”,”A”}

c) char name[6]={‘I’,’N’,’D’,’I’,’A’}

d) char name[] ; name=”INDIA”

38. what is the way to initialize array?

a) int num[6] = {2,4,12,5,45,5};

b) int n{} ={2,4,12,5,45,5};

c) int n{6}={2,4,12};

d) int n(6)={2,4,12,5,45,5};

39. what will be the output of the program?

a) 3, 2,15

b) 2, 3, 20

c)2, 1, 15

d) 1, 2, 5
Answer: Option A
Solution:
>> int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with a size of 5 and it is initialized to
a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25.

>> int i, j, m; The variable i, j, m are declared as an integer type.

>> i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2

>> j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.

>> m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means 2++ so i=3)

>> printf("%d, %d, %d", i, j, m); It prints the value of the variables i, j, m

Hence the output of the program is 3, 2, 15.

39. what will be the output of the program?

a) 5

b) 6

c) 9

d) Error

e) None of the above


Answer: Option C
Solution:

x[i] is equivalent to *(x + i),

so (buf + 1)[5] is *(buf + 1 + 5), i.e. buf[6].

40) An array elements are always stored in ____________memory locations

a) sequential

b) Random

c) Sequential and Random

d) None of the above

41) Let x be an array. which of the following operations are illegal?


a) ++x b) x+1 c)x++ d) x*2

options:

a) I and II

b) I,II and III

c) II and III

d) I, III and IV

e) III and IV
Answer: Option D
Solution: int x[10]; * x will store the base address of array. *
Statement I, III and IV is invalid.

Statement I and III : ++x and x++ are throwing en error while compile (lvalue required as increment operand )
Since, x is storing in the address of the array which is static value which cannot be change by the operand.

Statement IV : x*2 is also throw an error while compile (invalid operands to binary * (have 'int *' and 'int') )

Statement II : x+1 is throw a warning: assignment makes integer from pointer without a cast [enabled by
default]

42) what is the maximum number of dimensions an array in c may have?

a) 2

b) 8

c) 20

d)50

e) theoretically no limit. the only practical limits are memory size and compilers

43) size of the array need not be specified, when

a) initialized is a part of definition

b) it's a declaration

c) it is a formal parameter

d) All of these

44) what will be the output of the program?


a) Equal

b) Unequal

c) Error

d) None of these

Answer: Option B
Solution:
Strings are compared using strcmp() function defined under string.h header file.

45)

Unit-2 PART -B

1. Give the general syntax of conditional operator?


2. Define operator in C. What role an operator plays in C program?
3. Differentiate between relational and logical operators used in C?
4. Give the types of decision making statements
5. What is the general form of switch statement?
6. Differentiate do... while.. and while... loop.
7. Determine the output of the following and justify your answer

int main()
{
int ch; printf("enter a value between 1 to 2:");
scanf("%d", &ch);
switch (ch, ch -1){
case 1: printf("1\n"); break;
case 2: printf("2"); break;
} return 0; }
8. Explain the limitations of arrays.
9. Give the steps of looping process.
10.Brief the use of continue, goto, break statement and give the syntax.
11.What are loop control structures? Explain for loop, while loop and do-while
loop with their syntax.
12.What do you mean by infinite loop? Give suitable of any infinite loop in a C
program.
13. Explain break and continue statements with examples.
14. Determine the output of the following program justify your answer in a few words.

int main() {
float f = 1.0;
switch(f) {
case 1.0: printf("one"); break;
case 2.0: printf("two"); break;
default: prinf("%f", f);
}}
15.Write a program to print series of number divisible by 3 from 1 to 100 using for
loop.
16.Write a C program to print 1, 2, 4, 8, 16, 32, 64 …..N using do….while loop
(Read N from user).
17.What are Arrays in C programming? Give the importance of Array in C
language
13. What are the rules to declare one dimensional array?

14. What do you mean by compile time initialization? Give suitable example of
Compile time initialization of C Array.
15. Describe the array index out of bound error in context of C array program.

PART C

1) Lucy is celebrating her 15th birthday. Her father promised her that he will buy her a new computer
on her birthday if she solves the question asked by him. He asks Lucy to find whether the year on
which she had born is leap year or not. Help her to solve this puzzle so that she celebrates her
birthday happily. If her birth year is 2016 and it is a leap year display 2016 is a leap year.? Else
display 2016 is not a leap year and check with other leap year conditions

2) Write a C program to print the multiplication table of an integer n upto m rows using a while loop

sample input and output

INPUT
5
4
OUTPUT
1*5=5
2*5=10
3*5=15
4*5=20

3) Write a program to generate a following @s triangle:


@@@@@
@@@@
@@@
@@
@

4) Write a program that determines a student’s grade. The program will read three scores and
determine the grade based on the following rules: score =90% =>grade=A , score >= 70%
and <90% => grade=B, score>=50% and <70% =>grade=C, score<50% =>grade=F

5) i)Why switch case is better than else..if... ladder. Justify.


ii)Write a program to read a value (1-7) and print the equivalent day of the week
(i.e. 1-SUN, 2-MON.....)
iii) Explain briefly about for loop and Nested for loop with suitable example

iv) Write a program to print the following pattern.


12345
1234
123
12
1

6.a. i) Write a C program to insert an element at a specified position in the array.

7) ) Write a program to generate a following patterns

a)

b)
c)

d)

e)

8) write c Program for Student mark list generation by using control and looping statements

9) write c program for digit rotation. "For any positive integer, we define a digit rotation as either
moving the first digit to the end of the number (left digit rotation), or the last digit to the front of the
number (right digit rotation). For example, the number 12345 could be left digit rotated to 23451, or right
digit rotated to 51234.

10) Write a program to find the sum of positive numbers in an array

11) write c program for palindrome strings , two strings A and B, each consisting of lower case alphabets.

12) Write a arithmetic operation menu driven program using while(1)

13) i) Write short notes on switch case.


ii) Program to create a simple calculator, Performing addition, subtraction, multiplication,
division depending the input from user.
14) i)write a C program to read 10 nos. and reverse it using array

ii)Concatenate two arrays of length minimum 5 numbers.

UNIT III

PART A
1 ) Which of the following is not possible statically in C?
a) Jagged Array
b) Rectangular Array
c) Cuboidal Array
d) Multidimensional Array

2) What is the output of this C code?


#include <stdio.h>
void main()
{
int a[2][3] = {1, 2, 3, 4, 5};
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
}

a) 1 2 3 4 5 0
b) 1 2 3 4 5 junk
c) 1 2 3 4 5 5
d) Run time error

3) Predict the output of below program:

#include <stdio.h>

int main()
{
int arr[5];

// Assume that base address of arr is 2000 and size of integer


// is 32 bit
arr++;
printf("%u", arr);

return 0;
}

a) 2002

b) 2004

c) 2020

d) lvalue required
4 ) Predict the output of below program:
#include <stdio.h>

int main()
{
int arr[5];
// Assume base address of arr is 2000 and size of integer is 32 bit
printf("%u %u", arr + 1, &arr + 1);
return 0;
}
i. 2004 2020

ii. 2004 2004

iii. 2004 Garbage Value

iv. The program fails to compile because address of operator cannot be used with
array name

5) Size of the array need not be specified, when

A. Initialization is a part of definition


B. It is a declaratrion

C.It is a formal parameter


D.All of these

6) While passing an array as an actual argument, the function call must have the array name
A. with empty brackets

B. with its size


C.alone

D.none of the above


7) The parameter passing mechanism for an array is

A.call by value
B.call by value-result

C.call by reference
D.none of these

8) Under which of the following conditions, the size of an one-dimensional array need not be
specified?
A.when initialization is a part of definition
B.when it is a declaration

C.when it is a formal parameter and an actual


argument

D.All of the above


9) If a two dimensional array is used as a formal parameter, then

A.both the subscripts may be left empty


B.the first (row) subscript may be left empty

C.the first subscript must be left empty


D.both the subscripts must be left empty

11) Choose the statement that best defines an array


A.It is a collection of items that share a common name

B.It is a collection of items that share a common name and occupy consecutive memory location
C.It is a collection of items of the same type and storage class that share a common name and
occupy consecutive memory locations
D.None of the above

12) Choose the correct statements


A.Array stores data of the same type

B.Array can be a part of a structure


C.Array of structure is allowed

D.All of the above

13) What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. int a[2][3] = {1, 2, 3, 4, 5};
5. int i = 0, j = 0;
6. for (i = 0; i < 2; i++)
7. for (j = 0; j < 3; j++)
8. printf("%d", a[i][j]);
9. }

a) 1 2 3 4 5 0
b) 1 2 3 4 5 junk
c) 1 2 3 4 5 5
d) Run time error

Answer: a

14) What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. int a[2][3] = {1, 2, 3, , 4, 5};
5. int i = 0, j = 0;
6. for (i = 0; i < 2; i++)
7. for (j = 0; j < 3; j++)
8. printf("%d", a[i][j]);
9. }

a) 1 2 3 junk 4 5
b) Compile time error
c) 1 2 3 0 4 5
d) 1 2 3 3 4 5
Answer: b
15. What is the output of this C code?

1. #include <stdio.h>
2. void f(int a[][3])
3. {
4. a[0][1] = 3;
5. int i = 0, j = 0;
6. for (i = 0; i < 2; i++)
7. for (j = 0; j < 3; j++)
8. printf("%d", a[i][j]);
9. }
10. void main()
11. {
12. int a[2][3] = {0};
13. f(a);
14. }

a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values

Answer: a

16. What is the output of this C code?

1. #include <stdio.h>
2. void f(int a[][])
3. {
4. a[0][1] = 3;
5. int i = 0, j = 0;
6. for (i = 0;i < 2; i++)
7. for (j = 0;j < 3; j++)
8. printf("%d", a[i][j]);
9. }
10. void main()
11. {
12. int a[2][3] = {0};
13. f(a);
14. }

a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values

Answer: c

17. What is the output of this C code?

1. #include <stdio.h>
2. void f(int a[2][])
3. {
4. a[0][1] = 3;
5. int i = 0, j = 0;
6. for (i = 0;i < 2; i++)
7. for (j = 0;j < 3; j++)
8. printf("%d", a[i][j]);
9. }
10. void main()
11. {
12. int a[2][3] = {0};
13. f(a);
14. }

a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values

Answer: c

18. Comment on the following statement:

int (*a)[7];
a) An array “a” of pointers.
b) A pointer “a” to an array.
c) A ragged array.
d) None of the mentioned

Answer: b

19. Comment on the 2 arrays regarding P and Q:

1. int *a1[8];
2. int *(a3[8]);
3. P. Array of pointers
4. Q. Pointer to an array

a) a1 is P, a2 is Q
b) a1 is P, a2 is P
c) a1 is Q, a2 is P
d) a1 is Q, a2 is Q

Answer: b

20. Which of the following is not possible statically in C?


a) Jagged Array
b) Rectangular Array
c) Cuboidal Array
d) Multidimensional Array

Answer: a

21. What is the correct syntax to send a 3-dimensional array as a parameter? (Assuming declaration int a[5][4][3];)
a) func(a);
b) func(&a);
c) func(*a);
d) func(**a);

Answer: a

22. Applications of multidimensional array are?


a) Matrix-Multiplication
b) Minimum Spanning Tree
c) Finding connectivity between nodes
d) All of the mentioned
Answer: d

23. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. int ary[2][3];
5. foo(ary);
6. }
7. void foo(int *ary[])
8. {
9. int i = 10, j = 2, k;
10. ary[0] = &i;
11. ary[1] = &j;
12. *ary[0] = 2;
13. for (k = 0;k < 2; k++)
14. printf("%d\n", *ary[k]);
15. }

a) 2 2
b) Compile time error
c) Undefined behaviour
d) 10 2

Answer: a

24. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. int ary[2][3];
5. foo(ary);
6. }
7. void foo(int (*ary)[3])
8. {
9. int i = 10, j = 2, k;
10. ary[0] = &i;
11. ary[1] = &j;
12. for (k = 0;k < 2; k++)
13. printf("%d\n", *ary[k]);
14. }

a) Compile time error


b) 10 2
c) Undefined behaviour
d) segmentation fault/code crash

Answer: a

25. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. foo(ary);
5. }
6. void foo(int **ary)
7. {
8. int i = 10, k = 10, j = 2;
9. int *ary[2];
10. ary[0] = &i;
11. ary[1] = &j;
12. printf("%d\n", ary[0][1]);
13. }

a) 10
b) 2
c) Compile time error
d) Undefined behaviour

Answer: d

26. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. int ary[2][3][4], j = 20;
5. ary[0][0] = &j;
6. printf("%d\n", *ary[0][0]);
7. }

a) Compile time error


b) 20
c) Address of j
d) Undefined behaviour

Answer: a

27. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. int ary[2][3];
5. ary[][] = {{1, 2, 3}, {4, 5, 6}};
6. printf("%d\n", ary[1][0]);
7. }

a) Compile time error


b) 4
c) 1
d) 2

Answer: a

28. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. void foo();
5. printf("1 ");
6. foo();
7. }
8. void foo()
9. {
10. printf("2 ");
11. }

a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler

Answer: a

29. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. void foo(), f();
5. f();
6. }
7. void foo()
8. {
9. printf("2 ");
10. }
11. void f()
12. {
13. printf("1 ");
14. foo();
15. }

a) Compile time error as foo is local to main


b) 1 2
c) 2 1
d) Compile time error due to declaration of functions inside main

Answer: b

30. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. void foo();
5. void f()
6. {
7. foo();
8. }
9. f();
10. }
11. void foo()
12. {
13. printf("2 ");
14. }

a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler

Answer: d
Explanation: Even though the answer is 2, this code will compile fine only with gcc. GNU C supports nesting of functions in C
as a language extension whereas standard C compiler doesn’t.
31. What is the output of this C code?

1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo();
6. foo();
7. return 0;
8. }
9. void foo()
10. {
11. printf("2 ");
12. }
a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard

Answer: b

32. What is the output of this C code?

1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo(int);
6. foo(1);
7. return 0;
8. }
9. void foo(int i)
10. {
11. printf("2 ");
12. }

a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard

Answer: a

33. What is the output of this C code?

1. #include <stdio.h>
2. void foo();
3. int main()
4. {
5. void foo(int);
6. foo();
7. return 0;
8. }
9. void foo()
10. {
11. printf("2 ");
12. }

a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard

Answer: b

34. What is the output of this C code?

1. include <stdio.h>
2. void m()
3. {
4. printf("hi");
5. }
6. void main()
7. {
8. m();
9. }

a) hi
b) Run time error
c) Nothing
d) Varies
Answer: a

35. What is the output of this C code?

1. #include <stdio.h>
2. void m();
3. void n()
4. {
5. m();
6. }
7. void main()
8. {
9. void m()
10. {
11. printf("hi");
12. }
13. }

a) hi
b) Compile time error
c) Nothing
d) Varies

Answer: b

36. What is the return-type of the function sqrt()


a) int
b) float
c) double
d) depends on the data type of the parameter

Answer: c

37. Which of the following function declaration is illegal?


a) double func();
int main(){}
double func(){}
b) double func(){};
int main(){}
c) int main()
{
double func();
}
double func(){//statements}
d) None of the mentioned

Answer: d

38. What is the output of this code having void return-type function?

1. #include <stdio.h>
2. void foo()
3. {
4. return 1;
5. }
6. void main()
7. {
8. int x = 0;
9. x = foo();
10. printf("%d", x);
11. }

a) 1
b) 0
c) Runtime error
d) Compile time error

Answer: d

39. What will be the data type returned for the following function?

1. #include <stdio.h>
2. int func()
3. {
4. return (double)(char)5.0;
5. }
a) char
b) int
c) double
d) multiple type-casting in return is illegal

Answer: b

40. What is the problem in the following 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

Answer: d

41. The output of the code below is

1. #include <stdio.h>
2. void main()
3. {
4. int k = m();
5. printf("%d", k);
6. }
7. void m()
8. {
9. printf("hello");
10. }

a) hello 5
b) Error
c) Nothing
d) Junk value

Answer: a

42. The output of the code below is

1. #include <stdio.h>
2. int *m()
3. {
4. int *p = 5;
5. return p;
6. }
7. void main()
8. {
9. int *k = m();
10. printf("%d", k);
11. }

a) 5
b) Junk value
c) 0
d) Error

Answer: a

43. The output of the code below is

1. #include <stdio.h>
2. int *m();
3. void main()
4. {
5. int *k = m();
6. printf("hello ");
7. printf("%d", k[0]);
8. }
9. int *m()
10. {
11. int a[2] = {5, 8};
12. return a;
13. }

a) hello 5 8
b) hello 5
c) hello followed by garbage value
d) Compilation error

Answer: c

Part B
1. What is the need for user defined function?
2. Write a multi function program
3. List the Elements of user defined function
4. Give short note on 2-D array processing.
5. Write a C program to find the length of a string.
6. HELLO encode it as IFMMP using array
7. Show the difference between actual and formal parameter in function with piece of code

8. Compare user define function vs System define function

9. List categories of function


10. Explain the concept of function call by reference with a sample program.
11. Explain the concept of function call by value with a sample program
12. Explain about functions with example
13. Discuss Character Arrays
14. Predict output of the following program (CLO3)

int main(){
inta[][]={{1,2},(3,4}};
int i,j;
for (i=0;i<2;i++)
for(j=0;j<2;j++)
printf(“%d”,a[i][j]);
retorn 0;
}
15. Why array index starts from zero?
16. Contrast function declaration vs function definition.
17. List the advantages of functions.
nd
18. Program to Find the 2 Largest Elements in an Array.

19. Write a program to convert the given string (srm university) Lower to upper case

20. Advantages and limitations of multi dimensional array initialization


21. Explain call by value and call by reference with an example
22. Common programming errors in 2D arrays
12. Explain String functions with example
PART C
1. Array construction for student mark list for 100 students. output need to display register number, marks of
five subjects , CGPA and PASS/Fail Status
2. Explain in details about String Functions: gets(), puts(), getchar(), putchar(), printf(), with an example
programs
3. i)Print the given pattern using 2-D array
1234567
23456
345
4
ii) Program to divide one array into two arrays
4. i) What are strings in C? Write a C program to read a string in lowercase and convert it to
uppercase.
ii) ) Illustrate call by value and call by reference with example for each.

5. i) Find the factorial of 10 using function recursion.


ii) What is a string? Explain any 5 string functions.
6. Explain in details about String Functions: atoi, strlen, strcat, strcmp with an example
7. Functions declaration and definition, Types: Call by Value & Call by Reference with example programs
8. Explain and write c program for Function with and without Arguments and no Return Values
9. Explain and write c program for Passing Array to Functions with return type, Recursion Functions
10. Write c program for Matrix Multiplication using Multi-dimensional array
11. Program to Delete duplicate elements from an array
INPUT
13453
OUTPUT
1345

b. Write a program to perform Matrix addition and Multiplication using 2-D arrays

12. i) State the importance of functions. List out the different types of Function
ii) Write a swap function using call by value and call by reference
iii) Write a C program to concatenate two strings.
iv) Write a program to read to strings and compare them and print a message that the first string
is equal, less or greater than the second one accordingly.
13. Write c program for Matrix addition and Matrix Transpose using multi dimensional array
14. Given a number , find whether it is a power of 2 or not
15. Write a C program to swap elements in cyclic order using call by reference.
UNIT 4

1. What is the output of this C code?

1. #include <stdio.h>
2. void foo(int*);
3. int main()
4. {
5. int i = 10;
6. foo((&i)++);
7. }
8. void foo(int *p)
9. {
10. printf("%d\n", *p);
11. }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash

Answer: c

2. What is the output of this C code?

1. #include <stdio.h>
2. void foo(int*);
3. int main()
4. {
5. int i = 10, *p = &i;
6. foo(p++);
7. }
8. void foo(int *p)
9. {
10. printf("%d\n", *p);
11. }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault

Answer: a
3. What is the output of this C code?

1. #include <stdio.h>
2. void foo(float *);
3. int main()
4. {
5. int i = 10, *p = &i;
6. foo(&i);
7. }
8. void foo(float *p)
9. {
10. printf("%f\n", *p);
11. }

a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour

Answer: b

4. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. int i = 97, *p = &i;
5. foo(&i);
6. printf("%d ", *p);
7. }
8. void foo(int *p)
9. {
10. int j = 2;
11. p = &j;
12. printf("%d ", *p);
13. }

a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash

Answer: a

5. What is the output of this C code?


1. #include <stdio.h>
2. int main()
3. {
4. int i = 97, *p = &i;
5. foo(&p);
6. printf("%d ", *p);
7. return 0;
8. }
9. void foo(int **p)
10. {
11. int j = 2;
12. *p = &j;
13. printf("%d ", **p);
14. }

a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash

Answer: a

6. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. int i = 11;
5. int *p = &i;
6. foo(&p);
7. printf("%d ", *p);
8. }
9. void foo(int *const *p)
10. {
11. int j = 10;
12. *p = &j;
13. printf("%d ", **p);
14. }

a) Compile time error


b) 10 10
c) Undefined behaviour
d) 10 11
Answer: a

7. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. int *p = &i;
6. foo(&p);
7. printf("%d ", *p);
8. printf("%d ", *p);
9. }
10. void foo(int **const p)
11. {
12. int j = 11;
13. *p = &j;
14. printf("%d ", **p);
15. }

a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash

Answer: b

8. What is the output of the code below?

1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. int *const p = &i;
6. foo(&p);
7. printf("%d\n", *p);
8. }
9. void foo(int **p)
10. {
11. int j = 11;
12. *p = &j;
13. printf("%d\n", **p);
14. }

a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash

Answer: a

9. Which of the following are correct syntaxes to send an array as a parameter to function:
a) func(&array);
b) func(#array);
c) func(*array);
d) func(array[size]);

Answer: a.

11. What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. int k = 5;
5. int *p = &k;
6. int **m = &p;
7. printf("%d%d%d\n", k, *p, **m);
8. }

a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Run time error

Answer: a

12. What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. int k = 5;
5. int *p = &k;
6. int **m = &p;
7. printf("%d%d%d\n", k, *p, **p);
8. }

a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error

Answer: d.
13. What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. int k = 5;
5. int *p = &k;
6. int **m = &p;
7. **m = 6;
8. printf("%d\n", k);
9. }

a) 5
b) Compile time error
c) 6
d) Junk

Answer: c

14. What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. int a[3] = {1, 2, 3};
5. int *p = a;
6. int *r = &p;
7. printf("%d", (**r));
8. }

a) 1
b) Compile time error
c) Address of a
d) Junk value

Answer: b

15. What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. int a[3] = {1, 2, 3};
5. int *p = a;
6. int **r = &p;
7. printf("%p %p", *r, a);
8. }

a) Different address is printed


b) 1 2
c) Same address is printed.
d) 1 1
View Answer
Answer: c
Explanation: None.
16. How many number of pointer (*) does C have against a pointer variable declaration?
a) 7
b) 127
c) 255
d) No limits.

Answer: d

17. What is the output of this C code?

1. #include <stdio.h>
2. int main()
3. {
4. int a = 1, b = 2, c = 3;
5. int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;
6. int **sptr = &ptr1; //-Ref
7. *sptr = ptr2;
8. }

a) ptr1 points to a
b) ptr1 points to b
c) sptr points to ptr2
d) None of the mentioned

Answer: b

18. What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. int a[3] = {1, 2, 3};
5. int *p = a;
6. int **r = &p;
7. printf("%p %p", *r, a);
8. }

a) Different address is printed


b) 1 2
c) Same address is printed.
d) 1 1

Answer: c

PART B

1) short notes on Passing Array Element to Function with an example


2) Explain Formal and Actual Parameters
3) Give the Advantages of using Functions ,
4) example program for Processor Directives and #define Directives
5) write a program for Pointer Declaration and dereferencing,
6) write a program for pointers, Void Pointers and size of Void Pointers
7. Write algorithm and pseudo code for leap year calculation. [CLO 1]
8. Contrast the declaration of break and continue in while and for loop with justification
[CLO 2]
9. Limitations of two dimensional arrays.

PART C

1) i) c program to read array elements and print the values with their address
ii) what is Pointers and address operator, explain with an example of Size of Pointer Variable and
Pointer, Operator
2) Explain in details with an example Pointer Declaration and dereferencing, pointers, Void Pointers and
size of Void Pointers
3) write program for Arithmetic Operations, Incrementing Pointers
4) what is Constant Pointers, Pointers to array elements and strings

5)what is function pointer & Array of Function Pointers with an example

6write the c program for Accessing Array of Function Pointers, Null Pointers

7) Justify and explain the different size of data types using pointer variables with example program.

8) i) write a c program to count vowels and consonants in a string using pointer

ii) Write call by reference and call by value with an example program
UNIT 5

Part A

1. Which of the following are themselves a collection of different data types?


a) string
b) structures
c) char
d) all of the mentioned
View Answer
Answer: b
Explanation: None.
2. User-defined data type can be derived by___________
a) struct
b) enum
c) typedef
d) all of the mentioned

Answer: d

3. Which operator connects the structure name to its member name?


a) –
b) <-
c) .
d) Both <- and .

Answer: c

4. Which of the following cannot be a structure member?


a) Another structure
b) Function
c) Array
d) None of the mentioned

Answer: b

5. Which of the following structure declaration will throw an error?


a) struct temp{}s;
main(){}
b) struct temp{};
struct temp s;
main(){}
c) struct temp s;
struct temp{};
main(){}
d) None of the mentioned

Answer: d

6. What is the output of this C code?

1. #include <stdio.h>
2. struct student
3. {
4. int no;
5. char name[20];
6. }
7. void main()
8. {
9. struct student s;
10. s.no = 8;
11. printf("hello");
12. }

a) Compile time error


b) Nothing
c) hello
d) Varies

Answer: a

7. What is the output of this C code?

1. #include <stdio.h>
2. struct student
3. {
4. int no = 5;
5. char name[20];
6. };
7. void main()
8. {
9. struct student s;
10. s.no = 8;
11. printf("hello");
12. }

a) Nothing
b) Compile time error
c) hello
d) Varies

Answer: b

8. What is the output of this C code?

1. #include <stdio.h>
2. struct student
3. {
4. int no;
5. char name[20];
6. };
7. void main()
8. {
9. student s;
10. s.no = 8;
11. printf("hello");
12. }

a) Nothing
b) hello
c) Compile time error
d) Varies

Answer: c

9. What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. struct student
5. {
6. int no;
7. char name[20];
8. };
9. struct student s;
10. s.no = 8;
11. printf("%d", s.no);
12. }

a) Nothing
b) Compile time error
c) Junk
d) 8

Answer: d

10. Can the above code be compiled successfully?

1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97, .f = 3, .k = 1};
11. printf("%f\n", x.f);
12. }

a) Yes
b) No
c) Depends on the standard
d) Depends on the platform

Answer: c

11. What is the output of this C code?

1. #include <stdio.h>
2. void main()
3. {
4. struct student
5. {
6. int no;
7. char name[20];
8. };
9. struct student s;
10. no = 8;
11. printf("%d", no);
12. }

a) Nothing
b) Compile time error
c) Junk
d) 8

Answer: b

12. Number of bytes in memory taken by the below structure is

1. #include <stdio.h>
2. struct test
3. {
4. int k;
5. char c;
6. };

a) Multiple of integer size


b) integer size+character size
c) Depends on the platform
d) Multiple of word size

Answer: a

13. What is the output of this C code?

1. #include <stdio.h>
2. struct
3. {
4. int k;
5. char c;
6. };
7. int main()
8. {
9. struct p;
10. p.k = 10;
11. printf("%d\n", p.k);
12. }

a) Compile time error


b) 10
c) Undefined behaviour
d) Segmentation fault

14. What is the output of this C code?

1. #include <stdio.h>
2. struct
3. {
4. int k;
5. char c;
6. } p;
7. int p = 10;
8. int main()
9. {
10. p.k = 10;
11. printf("%d %d\n", p.k, p);
12. }

a) Compile time error


b) 10 10
c) Depends on the standard
d) Depends on the compiler

Answer: a

15. What is the output of this C code?

1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. };
7. int p = 10;
8. int main()
9. {
10. struct p x;
11. x.k = 10;
12. printf("%d %d\n", x.k, p);
13. }

a) Compile time error


b) 10 10
c) Depends on the standard
d) Depends on the compiler
Answer: b

16. What is the output of this C code?

1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int p = 10;
9. int main()
10. {
11. struct p x = {1, 97};
12. printf("%f %d\n", x.f, p);
13. }

a) Compile time error


b) 0.000000 10
c) Somegarbage value 10
d) 0 10

Answer: b

17. What is the output of this C code(according to C99 standard)?


advertisement

1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97, .f = 3, .k = 1};
11. printf("%f\n", x.f);
12. }

a) 3.000000
b) Compile time error
c) Undefined behaviour
d) 1.000000
Answer: a

18. What is the output of this C code(according to C99 standard)?

1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97, .k = 1, 3};
11. printf("%f \n", x.f);
12. }

a) 3.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour

Answer: b

19. What is the output of this C code(according to C99 standard)?

1. #include <stdio.h>
2. struct p
3. {
4. int k;
5. char c;
6. float f;
7. };
8. int main()
9. {
10. struct p x = {.c = 97};
11. printf("%f\n", x.f);
12. }

a) 0.000000
b) Somegarbagevalue
c) Compile time error
d) None of the mentioned

Answer: a
PART B

1. Write algorithm and pseudo code for leap year calculation.


2. Contrast the declaration of break and continue in while and for loop with justification
3. Limitations of two dimensional arrays.
4. Explain about nested pre-processor MACRO
5. Categorize the basic operations that can be performed on a file with suitable declarations.
6. Write a c program to demonstrate double pointer for accessing the value of another pointer
7. Explain about file operations and mode with syntax.

8) explain shortly about Initializing Structure, Declaring structure, variable,


9) give the example of Structure using typedef, Accessing members
10)what is Nested structure, Accessing elements in a structure array,
11)write c program for Array of structure, Accessing elements in a structure array
12. Explain about file operations and mode with syntax.
13. Give a brief note about preprocessor directives.
14. Differentiate between a union and a structure.
15.Write a program to read a file character by character, and display it simultaneously on the
screen
16) write a program for Passing Array of structure to function,
17)write a program for Array of pointers to structures
18. Explain about nested pre-processor MACRO
19. Categorize the basic operations that can be performed on a file with suitable declarations.
20.Write a c program to demonstrate double pointer for accessing the value of another pointer

PART C

1) explain in details about Bit Manipulation to structure and Pointer, to structure, Union Basic and
declaration with an example
2) explain in details about Accessing Union Members Pointers to Union, Dynamic memory allocation,
mallaoc, realloc, free with an example

3) explain in details about Allocating Dynamic Array, Multidimensional array using dynamic memory
allocation with an example
4) Explain in details about array of structures and accessing elements in a structure array.

5)Write a c program to insert a line at the end of text file


6) write a program to copy the content from one file to another file
7) explain and write the program for library management system using union
8) write a c program for file: opening, defining, closing, File Modes, File Types, Writing contents into a
file
9) write a c program for Reading file contents, Appending an existing file
10)Differentiate between gets() and scanf()
(11)Write a program to convert the given string “hello world” to “dlrow olleh”.

12. Write a program that passes a pointer to a structure to a function

13 Briefly discuss about file operations in C


14) c program to read array elements and print the values with their address
32(a)Write a program that passes a pointer to a structure to a function
15) Justify and explain the different size of data types using pointer variables with example program.
[CLO 5]
(OR)
16) write a c program to count vowels and consonants in a string using pointer
32(b)Briefly discuss about file operations in C [CLO 5]
17) Write call by reference and call by value with an example program

18) a) i) Explain in details about array of structures and accessing elements in a structure array.

ii) Write a c program to insert a line at the end of text file

19) i) write a program to copy the content from one file to another file
ii) explain and write the program for library management system using union
SRM Institute of Science and Technology, Ramapuram
Department of Computer Science and Engineering

18CSS101J-Programming for Problem Solving

UNIT 1 MCQ

1. What is the value of variable z?


int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;
a) 9
b) 12
c) 16
d) 20
Answer: c

2. To represent two different conditions which of the following is used.

a) Rectangle

b) Diamond

c) Circle

d) Parallelogram

Ans B

3. Give the output of the following program?


#include <stdio.h>
main()
{
int a=9, b=9;
a=b++;
b=a++;
b=++b;
printf("%d %d",a,b);
}
a) 9,9
b) 10,10
c) 9,10
d) 10,9
Answer: b

4. In the below mentioned operators, which of the following has the highest precedence?
a) Unary +
b) *
c) >=
d) ==
Answer: a

5. What is the output of the given code?

counter = 2
while counter < 68
puts counter
counter**=2
end
a) 2 4 16 64
b) 2 4 16
c) 2 4 16 256
d) None of the mentioned
Answer: b

6. Which of the following is a valid assignment operator?


a) +=
b) -=
c) *=
d) All of the mentioned
Answer: d

7. The output for the following C code is?


#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
Answer: a

8. Give the correct answer for the following C code?


#include <stdio.h>
void main()
{
int x = 4, y, z;
y = --x;
z = x--;
printf("%d%d%d", x, y, z);
}
a) 3 2 3
b) 2 2 3
c) 3 2 2
d) 2 3 3
Answer: d

9. What will be the output of the following C code?

#include <stdio.h>
void main()
{
int x = 4;
int *p = &x;
int *k = p++;
int r = p - k;
printf("%d", r);
}
a) 4
b) 8
c) 1
d) Run time error
Answer: c

10. Among the following options, which is not a valid representation in bits?
a) 8-bit
b) 24-bit
c) 32-bit
d) 64-bit
Answer: b
11. Name the entities whose values can be changed?
a) Constants
b) Variables
c) Modules
d) Tokens
Answer: b

12. Which is not a basic data type ?


a) float
b) int
c) real
d) char
Answer: c

13. Name the correct default value of a Boolean type?


a) 0
b) 1
c) True
d) False
e) -1
Answer: Option D

14. Which of the statements given below are correct?


1. We can assign values of any type to variables of type object.
2. When a variable of a value type is converted to object, it is said to be unboxed.
3. When a variable of type object is converted to a value type, it is said to be boxed.
4. Boolean variable cannot have a value of null.
5. When a value type is boxed, an entirely new object must be allocated and constructed.
a) 2, 5
b) 1, 5
c) 3, 4
d) 2, 3
Answer: Option B

15. Name the correct ways to set a value as 3.14 in a variable pi such that it cannot be modified?
a) float pi = 3.14F;
b) #define pi 3.14F;
c) const float pi = 3.14F;
d) const float pi; pi = 3.14F;
e) pi = 3.14F;
Answer: C

16. why the variable names beginning with underscore is not encouraged?
a) It is not standard form
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system
Ans:c

17. Mention the variable name which is not valid in C ?


a) int number;
b) float rate;
c) int variable_count;
d) int $main;
Ans:d

18. Which among the following options is true for the variable names in C?
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names can’t start with a digit
d) Variable can be of any length
Ans:c

19. Give the output for the following code?


#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

20. Which of the following can never be a variable name in C?


a) friend
b) true
c) volatile
d) export
Ans: c

21. Mention the User-defined data type from the following?


a) struct {char name[10], int age};
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) typedef int Boolean;
d) all of the mentioned
Answer:d

22. What is short int in C programming?


a) Basic datatype of C
b) Qualifier
c) short is the qualifier and int is the basic data type
d) All of the mentioned
Ans:c

23. What is the output of this C code?


#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

24. Which of the data types have size that is in variable?


a) int
b) struct
c) float
d) double
Ans:b

25. Mention the User-defined data type?


a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) struct {char name[10], int age};
d) All of the mentioned
Answer: Option D

26. Output of this C code is ?

int main()
{
char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
a) 128
b) – 128
c) Depends on the compiler
d) None of the mentioned
Answer: Option B

27. What is the output for the C program ?


#include <stdio.h>
int main()
{
static int i=5;
if (--i){
printf("%d ",i);
main();
}
}
a) 4321
b) 1234
c) 4444
d) 0000

Answer: A

28. Which of the following is not a storage class in C?


a) automatic storage class
b) register storage class
c) external storage class
d) internal storage class

Ans: d

29. Scope of which of these in C is not local to the block in which it is defined
a) automatic storage class
b) register storage class
c) static storage class
d) external storage class
Ans d

30. Single line comments are denoted by _____.


a) //
b) \\\\
c) /*
d) */
Answer: A

31 . How many comment lines are present in the below program -


main()
{
printf(\"Hello World in C //Comment \");
printf(\"Hello World in C \"); //Comment
//Comment printf(\"Hello World in C \");
}
a) 1
b) 0
c) 2
d) 3
Answer: C
32. Comments are case Sensitive !
a) True
b) False
Answer: B
33. What is the use of getchar()?
a) The next input character each time it is called
b) EOF when it encounters end of file
c) The next input character each time it is called EOF when it encounters end of file
d) None of the mentioned
Answer: c

34. Name the method which uses a list of well-defined instructions to complete a task
a) Algorithm
b) Flowchart
c) Programs
d) Functions
Ans C

35. Sequence logic will not be used while


a) Accepting input from the user
b) Giving output to the user
c) Adding two numbers
d) Comparing two sets of data
Ans B

36. Flowchart and algorithms are used for


a) Better programming
b) Easy understanding and debugging
c) Efficient coding
d) All the above
Ans d

37. What is the default initial value of static storage class?


a) 0
b) garbage value
c) 1
d) -1
Ans a

38. Resolving errors in a program is known as...

a) Debugging
b) Refixing
c) Error Checking
d) Problem Solving
Ans a
39. Many features of C were derived from an earlier language called _____.
a) FORTRAN
b) BASIC
c) B
d) PASCAL
Ans C

40. C Programming was created at ?


a) MIT University
b) AT&T Bell Laboratory
c) L&T Laboratory
d) Haward University
Ans B

41. What will be the output of the following pseudocode?


Integer a, b
Set a = 15, b = 7
a = a mod (a - 3)
b = b mod (b – 3)
a = a mod 1
b = b mod 1
Print a + b
a) 15
b) 7
c) 2
d) 0
[Note-mod finds the remainder after the division of one number by another. For example, the
expression “5 mod 2” leaves a quotient of 2 and a remainder of 1]
Answer: d

42. What will be the output of the following pseudocode?


Integer a, b, c
Set b = 5, a = 2, c = 2
if(b>a && a>c && c>b)
b=a+1
Else
a=b+1
End if
Print a + b + c
[Note-&&: Logical AND - The logical AND operator (&&) returns the Boolean value true(or 1)
if both operands--. If (x) gets executed if the value if(), i.e., x is not zero]
a) 2
b) 13
c) 26
d) 5
Ans:B
UNIT 2 MCQ

1. Does rational operators in the C language are calculated with the short circuit?
a) True
b) False
c) Depends on the compiler
d) Depends on the standard

Answer: a

2. What is the outcome of relational or logical operation in C?


a) True or False
b) 0 or 1
c) 0 if an expression is false and any positive number if an expression is true
d) None of the mentioned

Answer: b

3. What will be the output of the following C code?

#include <stdio.h>
int main()
{
int a = 20, b = 10, c = 10;
int d;
d = b + c == a;
printf("%d", d);
}
a)Syntaxerror
b1
c)5
d) 10

Answer: b
4. What will be the output of the following C program.

#include<stdio.h>
int main()
{ int a=-1, b=1, c, d;
c = !a && b;
d = !a || b;
printf("%d %d %d %d",a,b,c,d);
return 0;
}

a) -1 1 1 0
b) -1 1 0 0
c) -1 1 1 1
d) -1 1 0 1

Ans:- d

5. Which operator of the following is not a logical or relational operator?


a) !=
b) ==
c) ||
d) =

Answer: d
6. Relational operators will not be used in ____________
a) structure
b) long
c) strings
d) float
Answer: a

7. Which are the operators used to relate the values of operands to create logical value in C
language?

a) Logical operator
b) Relational operator
c) Assignment operator
) None of the above
Answer: b

8. In the following operators which one performs processes on data in binary level?

a)Logical operator
b)Bitwise operator
c) Additional operators
d)None of the above

Answer: b

9. How many number of operands needed to unary operator logical not (!)?

a)4

b)3

c)2

d)1

Answer: d

10. An expression comprises relational, arithmetic and assignment operators. If interpolations


are not indicated, the order of valuation of the operators will be:

a) Assignment, arithmetic, relational

b) Relational, assignment, arithmetic

c) Assignment, relational, arithmetic

d) Arithmetic, relational, assignment

Answer: d

11. Which group has higher priority between (>,<=,<,<==) and (==,!=)?

a) (>, >=, <, <=) has lower priority (==, !=)


b) (>, >=, <, <=) has higher priority (==, !=)
c) (>, >=, <, <=) has equal priority with (==, !=)
d) None of the above

Answer: b
12. The || and && operators

A. Relate two Boolean values


B. Relate two numeric values
C. Combine two Boolean values
D. Combine two numeric values

Answer: C

13. Increment operators need L-value Expression What will be the output of the following
program?

#include<stdio.h>
int main()
{ int i = 10;
printf("%d", ++(-i));
return 0;
}
A) 11
B) 10
C) -9
D) None – l-value required

Answer: D
14. What will be the output of the following C program?

#include <stdio.h>
int main()
{ int a = 3, b = -8, c = 2;
printf("%d", a % b / c);
return 0; }
A) 1
B) 15
C) -9
D) 12

Answer: A

15. What will be the output of the following C code?

#include <stdio.h>
void main()
{ double x = 123828749.66;
int y = x;
printf("%d\n", y);
printf("%lf\n", y);}
a) 0, 0.0
b) 123828749, 123828749.66
c) 12382874, 12382874.0
d) 123828749, 0.000000

Answer: d
16. Which of the following selection statement test only equality?
a) if
b) switch
c) if & switch
d) none of the mentioned
Answer: b

17. Which of the following will execute the body of loop condition is false?

a) do-while
b) while
c) for
d) none of the mentioned

Answer: a

18. Which of this following statement is incorrect?

a) switch statement is more efficient than a set of nested ifs


b) two case constants in the same switch can have identical values
c) switch statement can only test for equality, whereas if statement can evaluate any type
of Boolean expression
d) it is possible to create a nested switch statements

Answer: b
19. The break statement is used to quite from:

a. DO loop
b. FOR loop
c. SWITCH SATEMENT
d. All of above.

Answer: d

20. The advantage of a SWITCH statement over an ELSE-IF statement:

a. A default condition can be used in the SWITCH.


b. It is easier to understand.
c. Several conditions can cause one set of statements to be executed in a SWITCH.
d. Several diffeent statements can be executed in a SWITCH.

Answer: b

21. The comma (,) operator is primarily used in conjunction with:


a. FOR statement.
b. IF-ELSE statement.
c. DO-While statement.
d. All of above.

Answer: a

22. The GOTO statement is used:

a. To permit two dissimilar expressions to appear in condition where only one expression
would ordinarily use.
b. to dismiss loops or to exit from a switch.
c. an unconditional transfer of control to a named label.
d. to carry out a logical test and then take one of two possible actions, depending upon the
outcome of a test.
Answer: c
23. What is an Array in C language?

A) A group of elements of same data type.


B) An array contains more than one element
C) Array elements are stored in memory in continuous or contiguous locations.
D) All the above.

Answer :d
24. An array Index starts with?
A) -1
B) 0
C) 1
D) 2

Answer :b

25. What is the output of c program?


Int main()
{
Int a[]={5,2,3,4};
Int b[4]={10,6,7,8};
Printf(“%d,%d”, a[0], b[0]);
}
A) 5,10
B) 2,6
C) 0 0
D) Compiler error

Answer : A

26. Which is correct format for initializing an array in C?

a) int arr[5] = (1,2,3,4,5);


b) int arr(3) = {1,2,3,4,5};
c) int arr[3] = {1,2,3,4,5};
d) int arr(3) = (1,2,3,4,5);

Answer: c

27. Which of the following concepts make extensive use of arrays?


a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality

Answer: d
28. What are the disadvantages of arrays?

a) Data structure like queue or stack cannot be implemented


b) There are chances of wastage of memory space if elements inserted in an array are
lesser than the allocated size
c) Index value of an array can be negative
d) Elements are sequentially accessed

Answer: b

29. Array is accessed by _____________ elements.


a) randomly
b) sequentially
c) exponentially
d) logarithmically

Answer: a

30. What is the output of C program with arrays?

int main()

{char str[]={"C","A","T","\0"};

printf("%s",str);

return 0;}

A) C
B) CAT
C) CAT\0
D) Compiler error

Answer: D

31. What is the output of C program with string arrays?

int main()
{ char *p1 = "GOAT";
char *p2;
p2 = p1;
p2="ANT";
printf("%s", p1);
}
A) ANT
B) GOAT
C) G
D) A

Answer: B

32. A one-dimensional array contains one-dimensional arrays is called


A. Two-dimensional array
B. Multi-casting array
C. Multi-dimensional array
D. Three-dimensional array
Answer: A

33. Objects in a sequence that have the same type, is called


A. Arrays
B. Operators
C. Functions
D. Stacks
Answer: A

34. In an array starting from the beginning and inspecting each element one after other for
finding an object, until the object is found is called as
A. Linear search algorithm
B. Searching
C. Inspecting
D. All of them
Answer: A

35. Which of the following technique is used to find value in an array?


A. Binary search algorithm
B. Bubble sort
C. Linear search algorithm
D. All of them
Answer: d

36. Programmer’s uses _______ for defining their own types.?


A. Algorithms
B. Operators
C. Enumerations
D. None of them
Answer: c

37. A I-D array is considered as____?


A. Complex
B. Sequential
C. Linear
D. Both C and B
Answer: d

38. Array comprising elements are numbered as 0,1,2,3? These numbers are called as
A. Subscripts of the array
B. Index values
C. Members of an array
D. Both A and B
Answer: d

39. Find the output of the code

#include<stdio.h>
void main()
{
int m[5]={10,20,30,40,50);
int a,b,c;
a=++m[1];
b=m[1]++
c=m[i++];
printf(“%d,%d,%d”,a,b,c);
}

A. 21,20,30
B. 20,21,30
C. 22,21,30
D. 20,21,40
Answer : C

40. What will be the resulting array after rotating arr[]={2, 4, 6, 8, 10} by 2?
A. 4, 6, 8, 10, 2
B. 10, 2, 4, 6, 8
C. 8, 10, 2, 4, 6
D. 6, 8, 10, 2, 4

Answer : D

41. Which one is used in arrays extensively


A. Scheduling
B. Caching
C. Spatial Locality
D. Binary trees

Answer : C

42. What is the size of int arr[10] if the int is of 4 bytes?


A. 4
B. 40
C. 10
D. 14

Answer : B

43. The resulting array after reversing arr[]={21,23,25,27,29} is


A. 29,27,25,23,21
B. 25,27,29,21,23
C. 27,29,21,23,25
D. 23,25,27,29,21

Answer : A
44. Maximum number of dimensions an array have
A. 8
B. 4
C. No limit
D. 50
Answer : C

45. What does int arr[30] mean?


A. Array of size 30
B. Integer Array of size 30
C. Array of size 30 that have integer address
D. None

Answer : A
UNIT 3 MCQ

1. ___ quotes is used for character array initialization.


(A) Any
(B) Double
(C) No
(D) Single
Answer: B

2. Data type for array in C belongs to------------


(A) Primitive
(B) User defined
(C) Derived
(D) Basic
Answer: C

3. Two compare the two strings which of the following one is used
(A) Strcmp ()
(B) Strcpy ()
(C) Stcp()
(D) Stcmp()
Answer: A

4. ------------- Array example is matrix


(A) Single
(B) 2-D
(C) 3-D
(D) Multi-dimensional
Answer: B

5. Array Size should be always -----------


(A) Positive
(B) Negative
(C) Whole number
(D) Real number
Answer: A

6. The first subscript of 2D array represents the ----------- size


(A) Row
(B) Column
(C) Object
(D) Diagonal
Answer: A

7. _____ array is an array in which each element is itself an array


(A) 1-D
(B) 2-D
(C) 4-D
(D) 5-D
Answer: B

8. ---------- character type is used for indicating the terminator of the string.
(A) Float
(B) Int
(C) Null
(D) String
Answer: C

9. How many Array types available?


(A) 1
(B) 2
(C) 3
(D) 4
Answer: B
10. For write function, how many parameters required?
(A) Two
(B) Three
(C) Four
(D) Five
Answer: A
11. Arranging of elements in array with respect to ascending or descending is called ___
(A) Merging
(B) Filtering
(C) Sorting
(D) Ordering
Answer: C
12. The position of array elements always begins from ___
(A) One
(B) Two
(C) Three
(D) Zero
Answer: D

13. What will be the output of the following C code?

#include <stdio.h>

int main()

ARRAY1(ary);

void ARRAY1(int **ary)

int i = 10, k = 10, j = 2;

int *ary[2];

ary[0] = &i;
ary[1] = &j;

printf("%d\n", ary[0][1]);

a.22

b. Compile time error

c. Undefined behavior

d.102

Answer: c

14. What will be the output for the following program?

#include <stdio.h>

int main()

int ary[2][3];

ary[][] = {{1, 2, 3}, {4, 2, 6}};

printf("%d\n", ary[1][0]);

return 0;

a. 4

b. Compile time error

c.2

d.1

Answer: a

15. int (*b)[6];

a. An array “b” of pointers


b. A pointer “b” to an array

c. A ragged array

d. None of the mentioned

Answer: b

15. Statement on the following 2 arrays with respect to M and N.

int *x1[8];

int *(x2[8]);

M. Array of pointers

N. Pointer to an array

A) x1 is M x1 is N

B) x1 is M, x2 is M

C) x1 is N, x2 is M

D) x1 is N, x2 is N

Answer: b

16. Which of the following is not possible statically in C?

a. Jagged array

b. Rectangular array

c. Cuboidal array

d. Multidimensionl Array.

Answer:D

17. What will be the output of the following C code?


#include <stdio.h>

void main()

int a[2][3] = {1, 3, 5, 7, 9};

int i = 0, j = 0;

for (i = 0; i < 2; i++)

for (j = 0; j < 3; j++)

printf("%d", a[i][j]);

a.135790

b.13579junk

c.135799

d. Run time error

Answer: a

18. Write the output of the following C code?

#include <stdio.h>

int main()

char *S1 = "hello, world";

char *S2 = "hello, world";


if (strcmp(S1, S2))

printf("equal");

else

printf("unequal");

a.equal

b.Unequal

c.Compilation errot

d. Depends on the compiler

Answer: b

19. Write the output for the below code.

#include <stdio.h>

int main()

char *str = "hello, word\n";

printf("%d", strlen(str));

a. Compilation error
b. Undefined behavior

c.12

d.11

Answer: c

20. Always----------- function adds null character

a. strcmp()

b. strcat()

c. strcpy()

d. strrev()

Answer: b

21.----------- function is not declared in math.h ?


a) and()
b)pow()
c)exp()
d) acos()

Answer: a

22.Which one is correct for multidimensional array example.

a. int[][] code = {{1,2},{3,4,5}};

b. int[2][] code = {{1,2},{3,4,5}};

c. int[][] code={1,2,

3,4,5};

d. all

Answer: A
23. The function function1 is called __________ if it calls the same function function1.

A. indirect recursive
B. direct recursive
C. Both A and B
D. None of the above
Answer : B

24. Iteration not requires more system memory than recursion.

A. TRUE
B. FALSE
C. Can be true or false
D. Can not Say
Answer : A

25. Write the output of the following C code?

#include<stdio.h>

main()

int n;

n=f1(3);

printf("%d",n);

f1(int x)

int b;

if(x==1)

return 1;

else

b=x*f1(x-1);
return b;

a.6

b.4

c.12

d.10

Answer: a

26. Find the error of following function give on compilation ?

f(int a,int b)
{
int b;
a = 20;
return a;
}

a. Missing parentheses in return statement

b. Function should be define as int f(int a, int b)

c. Redeclaration if b

d. No error

Answer:c

27. It is essential to declare the sort of a function within the calling program on the off chance that
the function

a.Returns an integer

b.Returns a non-integer value

c.is not defined in the same file

d.None of these.
Answer:b

28. What is meant by void?

a. Representation of NULL data type


​b. Representation of void pointer
c. Error​​
d. None of above

Answer: A

29. If the two strings are not identical, then strcmp() function returns

a. -1​​
b. 0
c. 1​​
d. Yes

Answer: c

30.What is the Format specifier used to print a integer array in C Printf or Scanf function.?

A) %c

B) %C
C) %s
D) %d
Answer:D

31. Write the ouptu for the below code.

int main()

char ary[]="SRM IST";

printf("%s",ary);

return 0;

}
A) S

B) SRM
C) SRMIST
D) SRM IST
Answer : D

32.How do you convert this char array to string.?

char str[]={'g','o','o','d'};

A) str[4] = 0;

B) str[4] = '\0'

C) str[]={'g','o','o','d','\0'};

D) All the options

Answer : D

33.Find the output?

int main()

char str[]={"G","O","D","\0"};

printf("%s",str);

return 0;

A) Compiler error

B) GOD

C) GOD\0

D)G
Answer : A

34.What is the output of C Program with arrays.?

int main()

char str[100];

scanf("%s", str);

printf("%s",str);

return 0;

//input: WEST INDIES

A) WEST

B) WEST INDIES

C)W

D) Compiler error

Answer : D

35. What is the output of C Program with functions.?

int main()

FUN();

printf("LTD ");

return 0;

}
void FUN()

printf("HDFC ");

A) HDFC LTD

B) LTD HDFC

C) LTD

D) Compiler error

Answer : D

36. In C program, Function return ----------------- number of value at a time.?

A) Only One Value

B) Maximum of two values

C) Maximum of three values

D) Maximum of 8 values

Answer: A

37. Select the types of function

A) Library Functions

B) User Defined Functions

C) Both Library and User Defined

D) None

Answer: C

38. What is the constrain for number of functions in a C Program.?

A) 12
B) 24

C) 56

D) No limit

Answer: D

39. What is the least number of functions to be present in a C Program?

A) 1

B)3

C) 4

D) 2

Answer: A

40. Each C Program ought to contain which function.?

A) main()

B) show()

C) scanf()

D) printf()

Answer: A
UNIT 4 MCQ

1. How will you declare the function which is intended to receive an array as an argument
a. return_type function(type arrayname[])
b. return_type function(type arrayname[SIZE])
c. return_type function(type *arrayname)
d. All of the above

Ans: d

2. To store the array returned from the function, we can define a ______ which points to
that array.
a. Structure
b. Array
c. Pointer
d. List

Ans: c

3. The difference between Actual Parameters and Formal Parameters is that Actual
Parameters are the values that are ________ the function when it is invoked while Formal
Parameters are the variables defined by the function that _________ values when the
function is called.
a. Passed to, receives
b. Received by, pass
c. Prints, process
d. Process, prints

Ans: a

4. The advantages of using functions are:


a. Avoid repetition of codes.
b. Increases program readability.
c. Divide a complex problem into simpler ones.
d. All of the above
Ans: d
5. The C preprocessor is a __________ that is used automatically by the C compiler to
transform your program before actual compilation.
a. Macro processor
b. Microprocessor
c. Macro controller
d. Micorcontroller
Ans: a

6. Proprocessordirecives are executed ________ compilation.


a. Before
b. After
c. During
d. None of the above
Ans: a
7. The ________ preprocessor directive is used to paste code of given file into current file.
a. #define
b. #include
c. #ifdef
d. #pragma
Ans: b
8. A macro is a _________ which is replaced by the value of macro. Macro is defined
by ________ directive.
a. segment of code, #pragma
b. file, #define
c. segment of code, #define
d. none of the above
Ans: c
9. __________ is used to undefine a macro definition.
a. #udef
b. #unfed
c. #defun
d. #undef

Ans: d

10. What is the output of the following program?


#include<stdio.h>
#ifndef __MATH_H
#error First include then compile
#else
void main(){
float a;
a=sqrt(7);
printf("%f",a);
}
#endif
a. 2.64575
b. 49
c. 0.7
d. None of the above

Ans: a

11. The _____________ directive is used by the compiler to offer machine or


operating-system feature.
a. #define
b. #elif
c. #include
d. #pragma

Ans: d

12. Calculate the output of the following program?


#include<stdio.h>
#define Area(x) x*x
#define Costpaint(x,y,z) (z*y + Area (x))
void main()
{
int A = 8, B= 6, C = 4;
clrscr();
printf("The area of square= %d\n", Area(A));
printf("Cost of paint= %d\n", Costpaint(A,B,C));
}
a. 64
b. 88
c. 32
d. 76

Ans: b

13. Identify the value that gets printed in the following program

#include <stdio.h>
int main()
{
int a=10; //variable declaration
int *p; //pointer variable declaration
p=&a; //store address of variable a in pointer p
printf("Address stored in a variable p is:%x\n",p); //accessing the address
printf("Value stored in a variable p is:%d\n",**p); //accessing the value
return 0;
}
a. 10 10
b. 10, 60ff08
c. 60ffd, 10
d. None of the above

Ans: a

14. ___________ operator can be used to evaluate size of a variable/pointer in C.


a. size()
b. eval()
c. sizeof()
d. None of the above

Ans: c

15. A pointer to void means a ________ pointer that can point to any data type.
a. Specific
b. Generic
c. Exact
d. Null

Ans: b

16. Select the possible arithmetic operations are applicable on the pointer in C language:
a. Increment, Decrement
b. Addition, Subtraction
c. Comparison
d. All of the above

Ans: d

17. What is the output of the following program:

#include<stdio.h>
void main ()
{
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
int i;
printf("printing array elements...\n");
for(i = 0; i< 5; i++)
{
printf("%d ",*(p+i));
}
}
a. 1, 2, 3, 4, 5
b. 5, 4, 3, 2, 1
c. 1, 2, 3, 5, 8
d. None of the above

Ans: a

18. Identify the illegal pointer arithmetic operations:


a. Address + Address
b. Address * Address
c. Address % Address
d. All of the above

Ans: d

19. What is the output of the given program:

#include<stdio.h>
int addition ();
int main ()
{
int result;
int (*ptr)();
ptr = &addition;
result = (*ptr)();
printf("The sum is %d",result);
}
int addition()
{
int a=5, b=2;
return a+b;
}
a. 10
b. 3
c. 7
d. 25
Ans: c
20. A ______ pointer in C cannot change the address of the variable to which it is pointing
a. Fixed
b. Null
c. Void
d. Constant
Ans: d
21. An array of pointers to strings is an array of character pointers where each pointer points
to the ________ of the string or the __________ of the string.
a. first character, base address
b. last character, last address
c. middle character, middle address
d. None of the above
Ans: a
22. A function pointer points to _____, not ____.
a. data, code
b. code, data
c. type, const
d. None of the above
Ans: b
23. Identify the correct function pointer declaration:
a. int * foo(int)
b. int (*foo)(int);
c. int (int)(*foo)
d. None of the above
Ans: b
24. What is the output of the given program:
#include <stdio.h>
void Hi_function (int times); /* function */
int main() {
void (*function_ptr)(int); /* function pointer Declaration */
function_ptr = Hi_function; /* pointer assignment */
function_ptr (3); /* function call */
return 0;}
void Hi_function (int times) {
int k;
for (k = 0; k < times; k++) printf("Hi");}
a. Hi HiHiHiHiHi
b. Hi HiHiHiHi
c. Hi HiHiHi
d. Hi HiHi
Ans. d
25. What is the output of the given program:
#include <stdio.h>
void* cube (const void* num);
int main() {
int x, cube_int;
x = 4;
cube_int = cube (&x);
printf("%d cubed is %d\n", x, cube_int);
return 0;}

void* cube (const void *num) {


int result;
result = (*(int *)num) * (*(int *)num) * (*(int *)num);
return result;}
a. 2 cubed is 9
b. 3 cubed is 28
c. 4 cubed is 64
d. 5 cubed is 26
Ans. c
26. What is the output of the given program:
#include<stdio.h>
main (){
int a[3] = {10,20,30};
int *p[3],i;
for (i=0; i<3; i++)
p[i] = &a[i]; //initializing base address of array
printf (“elements of the array are”)
for (i=0; i<3; i++)
printf ("%d \t", *p[i]); //printing array of pointers
getch();
}
a. elements of the array are 10 20 30
b. elements of the array are 9 19 29
c. elements of the array are 11 21 31
d. None of the above
Ans. a
27. What is the output of the following program:
#include<stdio.h>
main (){
int a = 10;
int *p;
int **q;
p = &a;
q = &p;
printf("%d",a);
printf("%d", *p);
printf("%d", **q);
}
a. 10 10 11
b. 10 11 12
c. 10 10 10
d. None of the above
Ans. d
28. Choose the correct way of declaring pointer array:
a. datatype pointername [size];
b. datatype *pointername [size];
c. datatype[size]pointername;
d. None of the above
Ans. b
29. A ________ is a pointer that does not point to any memory location.
a. Null pointer
b. Void pointer
c. Array pointer
d. String pointer
Ans. a
30. The null pointer basically stores the ____ value.
a. Void
b. Int
c. Char
d. Null
Ans. d
31. __________ is used to initialize a pointer variable when the pointer does not point to a
valid memory address.
a. Void
b. Int
c. Char
d. Null
Ans. d
32. What is the output of the following program:
#include <stdio.h>
int main()
{
int *ptr;
printf("Address: %d", ptr);
printf("Value: %d", *ptr);
return 0;
}
a. Produces output
b. Program crashes
c. Show error
d. None of the above
Ans. b
33. What is the output of the following program:
#include <stdio.h>
int main()
{
int *ptr;
ptr=(int*)malloc(4*sizeof(int));
if(ptr==NULL)
{
printf("Memory is not allocated");
}
else
{
printf("Memory is allocated");
}
return 0;
}
a. Memory is not allocated
b. Memory is allocated
c. Shows compiler error
d. Program crashes
Ans. b
34. What is the output of the following program:
#include <stdio.h>
#include <conio.h>
#define NUMBER 0
void main() {
#if (NUMBER==0)
printf("Value of Number is: %d",NUMBER);
#endif
getch();
}
a. Value of Number is: 10
b. Value of Number is: 11
c. Value of Number is: 0
d. Value of Number is 9
Ans. c
35. The #error preprocessor directive indicates error. The compiler gives fatal error
if #error directive is found and skips further compilation process.
a. #ifdef, continue
b. #error, continue
c. #ifdef, skips
d. #error, skips
Ans. d
36. What is the output of the following program:
#include <stdio.h>
int main()
{
char *cities[] = {"Iran", "Iraq"};
int i;
for(i = 0; i< 2; i++)
printf("%s\n", cities[i]);
return 0;
}
a. Iraq, Iran
b. India, Iran
c. Iran, Iraq
d. Iraq, India
Ans. c
37. What is the output of the following program:
#include <stdio.h>
#include <string.h>
void function(char**);
int main()
{
char *str = "Pointer-to-string";
int i, j = strlen(str);
for(i = 0; i< j; i++)
printf("%c", *str++);
return 0;
}
a. gnirts-ot-retnioP
b. Pointers to string
c. Pointers-to-string
d. All of the above
Ans. c
38. Choose the correct way that express the Pointer and array elements
a. a[i]
b. i[a]
c. *(a + i)
d. All of the above

Ans. d

39. What is the output of the following program:


#include<stdio.h>
int main(){
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
k++;
printf("%d ",**k);
return 0;
}
a. Garbage Value
b. Compilation error
c. Runtime error
d. Linker error
Ans. c

40. What is the output of the following program:


#include<stdio.h>
int main(){
int i = 3;
int *j;
j = &i;
j++;
printf("%d ",*j);
return 0;
}
a. Garbage Value
b. Compilation error
c. Runtime error
d. Linker error
Ans.a
UNIT 5 MCQ

1. What is the output of the program?


#include <stdio.h>
struct student
{
char *name;
};
struct student s;
struct student fun(void)
{
s.name = "newton";
printf("%s\n", s.name);
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s\n", m.name);
m.name = "turing";
printf("%s\n", s.name);
}

a) newtonalanalan
b) run tiime error
c) alanalan newton
d) no error

Answer: a

2. What will be the output of the program?


#include <stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s, m;
s.name = "st";
m = s;
printf("%s%s", s.name, m.name);
}

a) Compile time error


b) no error
c) runtime error
d) stst

Answer: D

3. Which return-type cannot be used for a function?


a) main
b)int
c) void
d) none of the mentioned

Answer:D

4. What will be the output of the program?


#include <stdio.h>
struct temp
{
int a;
} s;
voidfunc(struct temp s)
{
s.a = 10;
printf("%d\t", s.a);
}
main()
{
func(s);
printf("%d\t", s.a);
}

a)0
b10 20
c) 10 0
d) (Garbage Value) 10

Answer:C

5. Which of the following is not possible??

a) s1 = s2;
b) s1 =! s2;
c) (*s1).number = 50;
d) None of the mentioned

Answer: D
6. Which operation is illegal in structures?

a) Typecasting of structure
b) none
c) Dynamic allocation of memory for structure
d) All

Answer: A

7. “s.t.b = 10” indicates __________

a) Syntax Error
b) Structure
c) float data type
d) variable name

Answer:B

8. What will be the output of theprogram?


#include <stdio.h>
struct student
{
char *name;
};
struct student fun(void)
{
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
s.name = "turing";
printf("%s", m.name);
}
a) alan
b) Runtime error
c) Compile time error
d) Noth

Answer:C
9. What will be the output of the program?
#include <stdio.h>
struct point
{
int x;
int y;
};
int main()
{
struct point p = {1};
struct point p1 = {1};
if(p == p1)
printf("equal\n");
else
printf("not equal\n");
}

a) Compile time error


b) Runtime error
c) depends on the standard
d) equal

Answer: a

10. What will be the output of theprogram?


#include <stdio.h>
struct point
{
int x;
int y;
};
structnotpoint
{
int x;
int y;
};
struct point foo();
int main()
{
struct point p = {1};
structnotpoint p1 = {2, 3};
p1 = foo();
printf("%d\n", p1.x);
}
struct point foo()
{
struct point temp = {1, 2};
return temp;
}
a) Compile time error
b) 1
c) Runtime error
d) Undefined behaviour

Answer: a

11. What will be the output of theprogram?


#include <stdio.h>
struct point
{
int x;
int y;
};
structnotpoint
{
int x;
int y;
};
int main()
{
struct point p = {1};
structnotpoint p1 = p;
printf("%d\n", p1.x);
}

a) Compile time error


b) 1
c) 0
d) Runtime error

Answer: a

12. What will be the output of theprogram?


#include <stdio.h>
struct point
{
int x;
int y;
};
structnotpoint
{
int x;
int y;
};
void foo(struct point);
int main()
{
structnotpoint p1 = {1, 2};
foo(p1);
}
void foo(struct point p)
{
printf("%d\n", p.x);
}

a) Compile time error


b) 1
c) 0
d) Runtime error

Answer: a

13. What will be the output of theprogram?


#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1 = {1, 2};
foo(&p1);
}
void foo(struct point *p)
{
printf("%d\n", *p.x++);
}

a) Compile time error


b) Segmentation fault
c)code crash
d) Runtime error

Answer: a

14. What will be the output of theprogram?


#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1 = {1, 2};
foo(&p1);
}
void foo(struct point *p)
{
printf("%d\n", *p->x++);
}
a) Compile time error
b) Runtime error
c) Segmentation fault
d) 5

Answer: a

15. What will be the output of theprogram?


#include <stdio.h>
struct student fun(void)
{
struct student
{
char *name;
};
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s", m.name);
}

a) Compile time error


b) Runtime error
c) Nothing
d) code crash
Answer: a

16. What will be the output of theprogram?


#include <stdio.h>
struct student
{char *name;
};
struct student fun(void)
{
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s", m.name);
}

a) Compiletime error
b) alan
c) Run time error
d) code crash

Answer: b

17. What is the correct syntax to access the member of the ith structure?
Assuming: struct temp
{
int b;
}s[50];
a) s.b.[i];
b) b[i].s;
c) b[i];
d) s[i].b;

Answer: d

18. What is the output of theprogram.


#include <stdio.h>
struct temp
{
int a;
int b;
int c;
};
main()
{
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}

a) No Compile time error, generates an array of structure of size 3


b) Compile time error, generates an array of structure of size 9
c) no Compile time error, illegal declaration of a multidimensional array
d) illegal assignment to members of structure

Answer: a

19. Which of the following uses structure?


a) Array
b) Binary Tree
c)linked list
d) All

Answer:D

20. What is the correct syntax to declare a function foo() which receives an array of structure in
function?
a) void foo(struct *var);
b) void foo(struct.var);
c) void(struct(var));
d) none

Answer: a

21. What is the output of the program( size of int be 4)


#include <stdio.h>
struct temp
{
int a;
int b;
int c;
} p[] = {0};
main()
{
printf("%d", sizeof(p));
}

a) 8
b) 12
c)30
d) Can’t be estimated
Answer: b

22. What is be the output of the program?


#include <stdio.h>
struct student
{
char *name;
};
struct student s[2];
void main()
{
s[0].name = "alan";
s[1] = s[0];
printf("%s%s", s[0].name, s[1].name);
s[1].name = "turing";
printf("%s%s", s[0].name, s[1].name);
}

a) alanalanalanturing
b) alanturingturing
c) alanturingturing
d) run time error

Answer: a

23. What isthe output of theprogram?


#include <stdio.h>
struct student
{
char *name;
};
struct student s[2], r[2];
void main()
{
s[0].name = "alan";
s[1] = s[0];
r = s;
printf("%s%s", r[0].name, r[1].name);
}

a)Runtime error
b) Compile time error
c) Varies
d) None

Answer: b
24. What is the output of the program?
#include <stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s[2], r[2];
s[1] = s[0] = "alan";
printf("%s%s", s[0].name, s[1].name);
}

a) alanalan
b) None
c) Compile time error
d) Runtime error

Answer: c

25. What is be the output of the program?


#include <stdio.h>
struct student
{
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}

a) 1
b) 8
c) 10
d) 0

Answer: d

26. What is the output of the program?


#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4};
foo(p1);
}
void foo(struct point p[])
{
printf("%d\n", p[1].x);
}

a) Compile time error


b) 3
c) 12
d) 4

Answer: b

27. What is the output of the program?

#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4};
foo(p1);
}
void foo(struct point p[])
{
printf("%d\n", p->x);
}

a) 1
b) 2
c) 4
d) Run time error

Answer: a

28. What is the output of theprogram?


#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, ++p->x);
}

a) 2 4
b) 2 2
c) Compile time error
d) Undefined

Answer: b

29. What is the output of the program?


#include <stdio.h>
struct point
{
int x;
int y;
} p[] = {1, 2, 3, 4, 5};
void foo(struct point*);
int main()
{
foo(p);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, p[2].y);
}

a) 1 0
b) Run time error
c) garbage value
d) Undefined

Answer: a

30. What is the output of the program?


#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, p[3].y);
}

a) Run time error


b) 2 0
c) 1 some garbage value
d) None

Answer: c

31. What is the output of the program?


#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, (p + 2).y);
}

a) Compile time error


b) 2 0
c) garbagevalue
d) Undefined

Answer: a
32. What is the output of the program?
#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, (p + 2)->y);
}

a) Runtime error
b) 1 0
c) garbagevalue
d) undefined

Answer: b

33. What is the output of the program?


#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}
a) 2
b) 3
c) 1
d) 8

Answer: d
34. What is the output of the program?
#include <stdio.h>
struct p
{
int x;
char y;
};
int main()
{
struct p p1[] = {1, 92, 3, 94, 5, 96};
struct p *ptr1 = p1;
int x = (sizeof(p1) / 3);
if (x == sizeof(int) + sizeof(char))
printf("%d\n", ptr1->x);
else
printf("falsen");
}

a) Compile time error


b)Runtime error
c) Undefined
d) false

Answer: d

35. What is the output of the program?


#include <stdio.h>
struct p
{
int x;
char y;
};
int main()
{
struct p p1[] = {1, 92, 3, 94, 5, 96};
struct p *ptr1 = p1;
int x = (sizeof(p1) / sizeof(ptr1));
if (x == 1)
printf("%d\n", ptr1->x);
else
printf("false\n");
}

a) Compile time error


b) Runtime error
c) false
d) Undefined

Answer: c
36. What is the output of the program?
#include <stdio.h>
struct p
{
int x;
char y;
};
typedefstruct p* q*;
int main()
{
struct p p1[] = {1, 92, 3, 94, 5, 96};
q ptr1 = p1;
printf("%d\n", ptr1->x);
}

a) Compile time error


b) Runtime errot
c) Undefined
d) Segmentation fault

Answer: a

37. What is the output of the program?


#include <stdio.h>
struct p
{
int x;
char y;
};
void foo(struct p* );
int main()
{
typedefstruct p* q;
struct p p1[] = {1, 92, 3, 94, 5, 96};
foo(p1);
}
void foo(struct p* p1)
{
q ptr1 = p1;
printf("%d\n", ptr1->x);
}

a) Compile time error


b) Runtime error
c) Segmentation fault
d) Undefined

Answer: a.

38. Which is an incorrect syntax for pointer to structure?


(Assuming structtemp{int b;}*my_struct;)
a) *my_struct.b = 10;
b) (*my_struct).b = 10;
c) my_struct->b = 10;
d) Both *my_struct.b = 10; and (*my_struct).b = 10;

Answer: a

39. Which is an incorrect syntax to pass by reference a member of a structure?


(Assume: structtemp{int a;}s;)
a) func(&s.a);
b) func(&(s).a);
c) func(&(s.a));
d) none of the mentioned

Answer: d

40. What is the output of the program?


#include <stdio.h>
struct temp
{
int a;
} s;
void change(struct temp);
main()
{
s.a = 10;
change(s);
printf("%d\n", s.a);
}
void change(struct temp s)
{
s.a = 1;
}
a) Output will be 20
b) Output will be 10
c) Output varies
d) Compile time error
Answer: b

You might also like