Download as pdf or txt
Download as pdf or txt
You are on page 1of 79

PROGRAMMING FOR PROBLEM SOLVING 2020-21

PROGRAMMING FOR PROBLEM SOLVING


Programming for Problem Solving
Course Outcome ( CO)
At the end of course , the student will be
able to understand
CO 1 To develop simple algorithms for arithmetic and logical problems.

CO 2 To translate the algorithms to programs & execution (in C language).

CO 3 To implement conditional branching, iteration and recursion.

CO 4 To decompose a problem into functions and synthesize a complete program using divide and
conquer approach.
CO 5 To use arrays, pointers and structures to develop algorithms and programs.

DETAILED SYLLABUS

Unit Topic

Introduction to Programming: Introduction to components of a computer system: Memory,


processor, I/O Devices, storage, operating system, Concept of assembler, compiler, interpreter, loader
I and linker.
Idea of Algorithm: Representation of Algorithm, Flowchart, Pseudo code with examples, From
algorithms to programs, source code.
Programming Basics: Structure of C program: writing and executing the first C program, Syntax and
logical errors in compilation, object and executable code. Components of C language: Standard I/O in
C, Fundamental data types, Variables and memory locations, Storage classes.
Arithmetic expressions and precedence : Operators and expression using numeric and relational
II operators, mixed operands, type conversion, logical operators, bit operations, assignment operator,
operator precedence and associatively.
Conditional Branching: Applying if and switch statements, nesting if and else, use of break and default
with switch.
Iteration and loops: use of while, do while and for loops, multiple loop variables, use of break and
continue statements.
III Functions: Introduction, types of functions, functions with array, passing parameters to functions, call by
value, call by reference, recursive functions.

Arrays: Array notation and representation, manipulating array elements, using multi dimensional arrays.
Character arrays and strings, Structure, union, enumerated data types, Array of structures, Passing arrays
IV to functions.
Basic Algorithms: Searching &Basic Sorting Algorithms (Bubble, Insertion and Selection), Finding roots
of equations, Notion of order of complexity.

Pointers: Introduction, declaration, applications, Introduction to dynamic memory allocation (malloc,


V calloc, realloc, free), Use of pointers in self-referential structures, notion of linked list (no
implementation)
File handling: File I/O functions, Standard C preprocessors, defining and calling macros, command-line
arguments.

1 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

PROGRAMMING FOR PROBLEM SOLVING


Solved MCQ
1. Introduction to components of a computer system ………………………...…….3

2. Idea of Algorithm: ……………………………………………….…………...…….9

3. Programming Basics: …………………………………………………..….....…... 13

4. Arithmetic expressions and precedence …………………………..…….…..…….18

5. Conditional Branching ………………………………………….....................…….28

6. Iteration and loops………………………………………………………………….34

7. Functions…………………………………………………………………………….42

8. Arrays and String …………………………………………………………………..51

9. Structure and Union ……………………………………………………….……….57

10. Basic Algorithms……………………………………………………………………63

11. Pointers…………………………………………………………………………..…..66

12. File handling……………………………………………………………………..….74

2 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

1. Introduction to components of a computer system


1. Which of the following is language processor? (c) Keyboard
(a) Compiler (d) Memory
(b) Interpreter Answer: Option (d)
(c) Assembler 7. Which is reffered to as the brain of the
(d) All of these computer?
Answer: Option (d) (a) Processor
2. ALU is? (b) RAM
(a) Array Logic Unit (c) ROM
(b) Application Logic Unit (d) Operating System
(c) Arithmetic Logic Unit Answer: Option (a)
(d) None of these 8. Which unit performs the all the arithmetic and
Answer: Option (c) logical operations in computer?
3. Which of the programming language is said to (a) CU (Control Unit)
be machine independent language? (b) ALU (Arithmetic and logical Unit)
(a) High Level language (c) Processor
(b) Machine Language (d) All of these
(c) Assembly Language Answer: Option (b)
(d) Cobol Langugage 9. Which standard is used to convert keystroke to
Answer: Option (a) corresponding bits
4. Which Translator can translate Assembly (a) ANSI
language program to Machine Language? (b) EBCDIC
(a) Compiler (c) ISO
(b) Interpreter (d) ASCII
(c) Debugger Answer: Option (d)
(d) Assembler 10. The memory capacity of a computer is
Answer: Option (d) represented in?
5. Which one of the following is known as the (a) Kilobits
'language of the computer'? (b) Kilobytes
(a) Programming language (c) Memory chips
(b) High-level language (d) None of above
(c) Machine Language Answer: Option (b)
(d) Assembly Language
11. Which of the following is non-volatile storage?
Answer: Option (c)
(a) Primary memory

6. Which is the critical component in any (b) Secondary Storage

computer? (c) Cache


(a) Mouse (d) ROM

(b) DVD Answer: Option (b)

3 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

12. RAM stands for (c) Electrically Erasable Programmable


(a) Read Access Memory Read-Only Memory
(b) Ready Application Module (d) None of these
(c) Random Access Memory Answer: Option (c)
(d) Remote access machine 18. Software required to run the hardware is known
Answer: Option (c) as
13. Keyboard is the _________ type of device? (a) Task Manager
(a) Printing (b) Task Bar
(b) Output (c) Program Manager
(c) Input (d) Device Driver
(d) Sound Answer: Option (d)
Answer: Option (c) 19. Which software is used to operate the computer
14. Microprocessor of computer system is a part of hardware and to provide a platform for running
__________ application software
(a) Memory (a) System Software
(b) Output Device (b) Software
(c) Input Device (c) Operating System
(d) Processing Unit (d) System Software
Answer: Option (d) Answer: Option (c)
15. The ALU of a computer responds to the 20. Which type of software are specific to user's
commands coming from need?
(a) Primary Memory
(a) Application Software
(b) Control Section
(b) System Software
(c) External Memory
(c) Software
(d) Cache Memory
(d) Operating System
Answer: Option (a)
Answer: Option (a)
16. Where the data and programs stored when the
21. RAM stands
processor uses them?
(a) Random Access Memory
(a) Main Memory
(b) Ready Application Module
(b) Secondary Memory
(c) Remote Access Machine
(c) Disk Memory
(d) Read Access Memory
(d) Hard Disk
Answer: Option (a)
Answer: Option (a)
17. EEPROM stands for
22. What type of memory is volatile?
(a) Electrically erasable Programmable
(a) Pen Drive
Read-Only Memory
(b) RAM
(b) Easily Erasable Programmable Read-
(c) ROM
Only Memory
(d) Hard Drive

4 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (b) (b) Printer


23. Which part of CPU perform calculations and (c) Light pen
make decision? (d) Scanner
(a) Alternate Logic Unit Answer: Option (d)
(b) Arithmetic Local Unit 29. ALU is
(c) Arithmetic Logic Unit (a) Array Logic Unit
(d) Alternate Local Unit (b) Application Logic Unit
Answer: Option (c) (c) Arithmetic Logic Unit
24. Which of the following is a part of primary (d) None of these
memory of computer Answer: Option (c)
(a) PROM 30. Operating system is installed on
(b) CD-ROM (a) Hard Disk
(c) Pen-drive (b) Cache memory
(d) Floppy Disk (c) Mother Board
Answer: Option (a) (d) None of these
25. Microprocessor of computer system is a part of Answer: Option (a)
:- 31. Which among following is not necessary for
(a) Memory working of a standalone computer?
(b) Input Device (a) RAM
(c) Output Device (b) Hard Drive
(d) Processing Unit (c) Operating System
Answer: Option (d) (d) LAN card
26. In the evaluation of a computer language, all of Answer: Option (d)
the following characteristics should be 32. Which the following is application software?
considered except? (a) Compiler
(a) Application-oriented features (b) Power Point
(b) Efficiency (c) Debugger
(c) Readability (d) None of the above
(d) Hardware maintenance costs Answer: Option (b)
Answer: Option (d) 33. Which of the programming language is said to
27. Keyboard is the type of device be machine independent language?
(a) Input (a) High Level Language
(b) Pointing (b) Machine Language
(c) Output (c) Assembly Language
(d) Sound (d) All the Above
Answer: Option (a) Answer: Option (a)
28. A document or image can be scanned in to 34. When a key is pressed on keyboard, which
digital form by using standard is used for converting the keystroke
(a) Marker into the corresponding bits

5 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(a) ANSI Answer: Option (c)


(b) ASCII 40. Which of the following is non-volatile storage?
(c) EBCDIC (a) Primary
(d) ISO (b) Secondary
Answer: Option (b) (c) Cache
35. What do you call the translator which takes (d) None of these
assembly language program as input and Answer: Option (b)
produce machine language code as output? 41. Which are the types of ROMs?
(a) Compiler (a) SROM & DROM
(b) Interpreter (b) PROM & EPROM
(c) Debugger (c) PROM & EROM
(d) Assembler (d) EROM & SROM
Answer: Option (d) Answer: Option (b)
36. Which one of the following is known as the 42. A non-erasable disk that stores digitized audio
‘language of the computer’? information is___
(a) Programming language (a) CD-RW
(b) High-level language (b) CD-ROM
(c) Machine language (c) DVD-RW
(d) Assembly language (d) None of these
Answer: Option (c) Answer: Option (b)
43. The two kinds of main memory are
37. Which of the following is language processor? (a) Primary and secondary
(a) Compiler (b) Random and sequential
(b) Interpreter (c) ROM and RAM
(c) Assembler (d) All of these
(d) All of these Answer: Option (c)
Answer: Option (d) 44. CD-ROM is a
38. Which smaller unit of the CPU performs all (a) Semiconductor memory
arithmetic and logic functions in a computer? (b) Memory register
(a) CU (c) Magnetic memory
(b) ALU (d) None of these
(c) Processor
(d) All of these Answer: Option (d)
Answer: Option (b) 45. The ALU of a computer responds to the
39. The smallest unit of data in a computer is __ commands coming from
(a) Byte (a) Primary memory
(b) Nibble (b) Control section
(c) Bit (c) External memory
(d) KB (d) Cache memory

6 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (c) (c) Assembler


46. Magnetic disks are the most popular medium (d) Simulator
for Answer: Option (a)
(a) Direct access 51. ________ is computer software designed to
(b) Sequential access operate the computer hardware and to provide a
(c) Both A and B platform for running application software
(d) None of these (a) Application software
Answer: Option (c) (b) System software
47. Where are data and programs stored when the (c) Software
processor uses them? (d) Operating system
(a) Main memory Answer: Option (d)
(b) Secondary memory 52. ________are specific to users’ needs
(c) Disk memory (a) Application software
(d) Hard disk (b) System software
Answer: Option (a) (c) Software
48. What characteristic of read-only memory (d) Operating system
(ROM) makes it useful? Answer: Option (a)
(a) ROM information can be easily updated. 53. C language was developed by
(b) Data in ROM is non-volatile, that is, it a) Dennis Ritchie
remains there even without electrical power. b) Bjarne Stroustrup
(c) ROM provides very large amounts of c) James Gosling
inexpensive data storage. d) Guido van Rossum
(d) ROM chips are easily swapped between Answer: Option (a)
different brands of computers. 54. The ALU of a computer
Answer: Option (b) a) Can perform logical operation only
49. EEPROM stands for b) Can perform arithmetic operation only
(a) Electrically Erasable Programmable Read- c) Can perform both arithmetic and logical
Only Memory operations
(b) Easily Erasable Programmable Read-Only d) None of the above.
Memory Answer: Option (c)
(c) Electrically Erasable Programmable Read-
Only Memory 55. Compiler helps in the translation from
(d) None of these a) Integer to binary
Answer: Option (c) b) High-level program to binary digits
50. A computer program that translates one c) High-level language to machine level
program instructions at a time into machine language
language is called______ d) Pseudo code to computer program
(a) Interpreter Answer: Option (c)
(b) Compiler

7 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

56. Computer memory which is used to store Answer: Option (b)


programs and data currently being processed by
CPU is
58. Application software is dependent on system
a) ROM
software. Syntax error occurs when
b) RAM
a) The rules of grammar of the programming
c) Cache memory
language is violated
d) PROM
b) The statements in the program have no
Answer: Option (b)
meaning
57. Which of the following statement is correct? c) The program gives wrong or undesired
a) System software is dependent on output
application software. d) Some illegal operation(e.g. divide by zero)
b) Application software is dependent on is done
system software. Answer: Option (a)
c) Both are independent of each other.
d) None of the above

8 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

2. Idea of Algorithm

1. What is algorithm? (d) Loop


(a) Step by step procedure for calculations Answer: Option (a)
(b) Application Code 5. The diamond symbol denotes ___________
(c) Type of programming languge (a) Process
(d) Compiler (b) Input/Output
Answer: Option (a) (c) Loop
2. A 2D diagram to represent the steps to be (d) Decision
followed to solve a problem is known as Answer: Option (d)
a) Flow-chart 6. A _________________ is diagram that
b) Pseudo-code depicts the flow of a program
c) Both (a) and (b) (a) Hashtable
d) d) None of these (b) Algorithm
Answer: Option (a) (c) Flowchart
3. Which one of the following statement is the (d) Graph
most appropriate? Answer: Option (c)
a) Flowchart is diagrammatic representation 7. What is algorithm?
of the algorithm. Pseudo code is just (a) Application code
another name of algorithm. (b) Type of programming language
b) Flowchart is basically a diagrammatic (c) Step by step procedure for calculations
representation of the algorithm. Whereas (d) None of these
in pseudo code normal English language is Answer: Option (c)
translated into the programming languages
to be worked on. 8. The rectangle symbol denotes _______
c) Pseudo code is basically a diagrammatic (a) Input/output
representation of the algorithm. Whereas (b) Process
in flowchart normal English language is (c) Decision
translated into the programming languages (d) Loop
to be worked on. Answer:Option (b)
d) Pseudo code is another name of
programming. Whereas in flowchart is 9. The parallelogram symbol denotes _______
diagrammatic representation of algorithm. (a) Input/output
Answer: Option (b) (b) Process
(c) Decision
4. In Flow chart rectangle symbol denotes ____? (d) Loop
(a) Process Answer: Option (a)
(b) Input/Output 10. The diamond symbol denotes _______
(c) Decision (a) Input/output

9 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(b) Process Answer: Option (a)


(c) Decision 16. Terminal symbol in a flowchart indicates
(d) Loop a) End
Answer: Option (c) b) processing
11. A _____ is a diagram that depicts the flow of c) Input and Output
a program d) Decision
(a) Algorithm Answer: Option (a)
(b) Hash Table
(c) Graph 17. Pseodocode is used for
(d) Flowchart a) Denoting the program
Answer: Option (d) b) Flow Program code
12. Step by step instructions used to solve a c) For coding the program
problem is ____ d) To write program steps
(a) Program e) Answer: Option (c)
(b) Flowchart
(c) Algorithm
18. What are the three algorithm constructs?
(d) Instructions
a) Sequence, selection, repetition
Answer: Option (c) b) Input, output, process
13. The _____ provides a pictorial representation c) Input/output, decision, terminator
of a given problem. d) Loop, input/output, process
Answer: Option (a)
(a) Algorithm
(b) Flowchart
19. What is the difference between a
(c) Pseudocode
(d) All of these
flowchart and pseudocode?

Answer: Option (b) a) A flowchart is diagramatic whilst


pseudocode is written in a programming
language (eg. Pascal or Java)
14. Macro flowchart is also called as b) A flowchart is textual but pseudocode is
a) Simple detailed flowchart diagrammatic
b) Less Detail flowchart c) A flowchart is a diagrammatic
description of an algorithm whilst
c) More detail flowchart
pseudocode is a textual description of an
d) None algorithm
Answer: Option (b) d) A flwochart and pseudocode are the
same thing
Answer: Option (c)
15. GUI stands for
a) Graphical User Interface
20. In a flowchart a calculation (process) is
b) Graphical input Unit
represented by
c) Graph Under Instruction
a) A rectangle
d) None
b) A rhombus
c) A parallelogram
10 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

d) A circle b) If the correct software is being used


Answer: Option (a) c) If there is more than one way of solving
the problem
21. A flowchart needs to represent the a Answer: Option (c)

situation where for each mark a student is


26. In a flowchart how are symbols
award 'Pass' or 'Fail'...the system will
connected?
consider the mark and if it's 50 or over
a) Symbols do not get connected together
award 'Pass', else it awards 'Fail'. This is in a flowchart
an example of which of the algorithm b) With lines and an arrow to show the
direction of flow
constructs?
c) With dashed lines and numbers
a) Decision d) With solid lines to link events
b) Loop Answer: Option (b)
c) Sequence
d) All of the above
Answer: Option (a) 27. When can algorithms be used?
a) Only with computers
22. What is a flowchart? b) Only when programming
a) A text-based way of designing an c) Only with flowcharts
algorithm d) Any time to design solutions to
b) A specific programming language problems
c) A diagram that represents a set of Answer: Option (d)
instructions
d) A bullet point list of instructions 28. A flowchart
Answer: Option (c)
a) Helps you plan out computer code
b) is a type of graphic diagram that
23. We can show the sequence of steps in an represents an algorithm,
algorithm in a structural diagram called a c) Uses shapes to help organize a process
d) All of the above
flow chart. Answer: Option (d)
a) True
29. What shape represents the start and end of
b) False
Answer: Option (a) a flowchart
a) Oval
24. When you write an algorithm the order of b) Rectangle
c) Diamond
the instructions is very important. d) Square
a) True Answer: Option (a)
b) False
30. What does an arrow represent in a flow
Answer: Option (a)
chart

25. What should be considered when a) Decision making


b) Data Flow
designing an algorithm? c) Start
a) If the correct hardware is being used d) Stop

11 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (b)

31. What does this pseudocode do?


print "Hello"
a) Nothing
b) Prints the word "Hello" to the output
c) hello is print in pseudocode
d) The code won't work
Answer: Option (b)

32. What is pseudocode?


a) Simplified programming language, that
is not a specific language
b) Complicated programming language
c) Simple programming language, which is
linked to a specific language
d) A type of cheese
Answer: Option (a)

12 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

3. Programming Basics

1. What is the starting point of c program Answer: Option (a)


execution? 6. How Many Keywords are there in C?
(a) #include (a) 31
(b) void main() (b) 32
(c) Opening curly braces '{' (c) 64
(d) None of these (d) 63
Answer: Option (b) Answer: Option (b)
2. C is a __________ language 7. Which of the following is true for variable
(a) High level name in C?
(b) Middle level (a) Variable names cannot start with a digit
(c) Machine level (b) Variable can be of any length
(d) Low level (c) They can contain alphanumeric characters
Answer: Option (b) as well as special characters
3. What symbol ends a statement in C program? (d) Reserved word can be used as a variable
(a) ; (Semicolon) name
(b) . (full stop) Answer: Option (a)
(c) : (Colon) 8. printf() belongs to which library of c
(d) } (curly braces) (a) stdlib.h
Answer: Option (a) (b) stdio.h
4. Which of the following statement is correct? (c) stdout.h
I. Keywords are those words whose meaning (d) stdoutput.h
is already defined by Compiler. Answer: Option (b)
II. Keywords cannot be used as variable 9. Which of the following is a correct statement?
name. (a) Variable name must start with underscore
III. There are 32 keywords in C. (b) Variable name must have digit
IV. C keywords are also called as reserved (c) variable name must have white space
words. character
a) I and II (d) Keyboard cannot be a variable name
b) II and III Answer: Option (d)
c) I, II and IV 10. Any C program
d) All of the above (a) must contain at least on function
Answer: Option (d) (b) need not contain any function
(c) needs input data
5. Header file is compulsory to include in a C (d) none of above
program printing "Hello World" Answer:Option (a)
(a) True 11. Which of the following is not a C variable?
(b) False a) Count123

13 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

b) Count_123 (d) $$
c) Count@123 Answer: Option (c)
d) X_123_Count
Answer: Option (c) 17. What will be the output of following program
12. A function #include
a) is a block of statements to perform some main()
specific task {
b) is a fundamental modular unit to perform int x,y = 10;
some task x = y * NULL;
c) has a name and can be used multiple times printf(\"%d\",x);
d) All the above options are true }
Answer: Option (d) (a) error
(b) 0
13. What should be written in the program to get (c) 10
newline on the screen? (d) garbage value
(a) printf("\n"); Answer: Option (a)
(b) echo"\n"
(c) printf('\n'); 18. printf() belongs to which library of c
(d) printf("\n"); (a) stdlib.h
Answer: Option (a) (b) stdio.h
14. A declaration float sum, value; occupies (c) stdout.h
_____ of memory? (d) stdoutput.h
(a) 2 byte Answer: Option (b)
(b) 4 byte 19. What will be printed if we type the statement
(c) 6 byte printf(“%d\n”,’d’);
(d) 8 byte (a) 0
Answer:Option (d) (b) 100
(c) error
15. MACRO is used to _______________. (d) d
(a) Save memory Answer: Option (b)
(b) fast execution
(c) Both a & b 20. Which of the following function is more
(d) none of above appropriate for reading in a multiword string?
Answer: Option (b) (a) printf();
16. Which of the following is a symbol for logical (b) scanf();
AND operator? (c) gets();
(a) II (d) puts();
(b) & Answer: Option (c)
(c) &&

14 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

21. What are the different types of real data types Answer: Option (a)
in C? 26. What should be written in the program to get
(a) float, double newline on the screen?
(b) short int, double, long int (a) printf(“\n”);
(c) double, long int, float (b) echo “\n”;
(d) float, double, long double (c) printf(‘\n’);
Answer: Option (d) (d) printf(“ \n “);
22. Which of the following is a correct statement? Answer: Option (a)
(a) Variable name must start with underscore
(b) Variable name must have digit 27. ASCII value of ‘a’ is
(c) Variable name must have white space (a) 97
character (b) 65
(d) Keyword cannot be a variable name (c) 47
Answer: Option (d) (d) None of the above
Answer: Option (a)
23. What will be the output of following code. 28. A float requires ______bytes in memory
{ (a) 2 bytes
int x = 10, y=15; (b) 1 byte
x = x++; (c) 8 bytes
y = ++y; (d) 4 bytes
printf(“%d, %d \n” , x, y); Answer: Option (d)
} 29. Which of the following operator is used to
(a) 10, 15 select a member of a structure variable
(b) 10, 16 (a) .(dot)
(c) 11, 16 (b) ,(comma)
(d) 11, 15 (c) : (colon)
Answer:Option (b) (d) ;(semicolon)
24. Any C program Answer: Otion (a)
(a) Must contain at least one function
(b) Need not contain any function 30. What is the starting point of C program
(c) Needs input data execution?
(d) None of the above (a) #include
Answer:mOption (a) (b) void main()
(c) Opening curly braces ‘{‘
25. Which is a correct ‘C’ expression? (d) None of these
(a) z = (x+y); Answer: Option (b)
(b) z = [x+y];
(c) z = {x+y}; 31. Which symbol ends a statement in C
(d) z = {(x+y)}; program?

15 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(a) . (full stop) 37. Which of the following is true for variable
(b) ; (semicolon) names in C?
(c) : (colon) (a) Variable names cannot start with a digit
(d) } (curly braces) (b) Variable can be of any length
Answer: Option (b) (c) They can contain alphanumeric characters
32. Which symbol is used to comment single as well as special characters
statement? (d) Reserved word can be used as a variable
(a) // name
(b) \ Answer: Option (a)
(c) /*
(d) \* 38. Character literal in C syntax is?
Answer: Option (a) (a) Z
33. Why preprocessor directive needed in the (b) ‘Z’
beginning of a C program? (c) “Z”
(a) To start execution of a program (d) None of these
(b) To include keywords in a program Answer: Option (b)
(c) To include files in a program 39. Choose the correct statement about C escape
(d) None of these sequences
Answer: Option (c) (a) \n produces a new line
34. Header file is compulsory to include in a C (b) \t produces one tab space (white spaces)
program printing “Hello World” (c) \b produces one backspace
(a) True (d) All of these
(b) False Answer: Option (d)
Answer: Option (a) 40. Choose a valid C format specifier
35. Which of the following is not a basic data (a) %d prints integer constants
type in C language? (b) %f prints float constants
(a) float (c) %c prints character constants
(b) int (d) All of these
(c) real Answer: Option (d)
(d) char 41. When we write X=10 and Y=X, which of the
Answer: following memory assignment is correct
Option (c) a) X and Y will have same location and 10
36. How many keywords are there in C? will be stored.
(a) 31 b) X and Y will have two distinct locations
(b) 32 and 10 will be stored in both.
(c) 64 c) X and Y will have same location and
(d) 63 only X will contain value 10
Answer: Option (b) d) X and Y will have two distinct locations
and only X will contain value 10

16 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (b) b) Which function is to use


42. which of the following is not a storage class c) Where to store the program
specifier? d) None of them
a) auto Answer: Option (a)
b) register 48. how many storage classes in c?
c) extern a) 2
d) volatile b) 3
Answer: Option (d) c) 4
43. what is the inital value of register storage d) 5
class specifier? Answer: Option (C)
a) 0
b) Null
c) Garbage
d) Infinite
Answer: Option (c)
44. What is the scope of extern class specifier?
a) Within block
b) Within Program
c) Global Multiple files
d) None of the above
Answer: Option (c)

45. What is the scope of static class specifier?


a) Within block
b) Within Program
c) Global Multiple files
d) None of the above
Answer: Option (a)

46. what is the inital value of extern storage class


specifier?
a) 0
b) Null
c) Garbage
d) Infinite
Answer: Option (a)
47. An identifier's storage class determines
a) The time during which the identifier
exists in memory

17 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

4. Arithmetic expressions and precedence

1. What is the putput? (a) =


void main() (b) =>
{ (c) ==
float a=654.1239; (d) >>
printf("%0.3f",a); Answer: Option (c)
} 6. What will be the value of variable a?
(a) Compiler error float a = 3.5+4.5;
(b) 654.123900 (a) a = 8.0
(c) 654.123 (b) a = 8
(d) 654.124 (c) a = 7
Answer: Option (d) (d) a = 0.0
2. Choose a C formatted Input-Output Answer: Option (a)
function below. 7. If we want to increment the value of sum
(a) printf(), scanf() by 1. Which of following should be used?
(b) sprintf(), sscanf() (a) sum++;
(c) fprintf(), fscanf() (b) sum = sum + 1;
(d) All of above (c) sum += 1;
Answer: Option (d) (d) all of above
3. Which operator if used to compare two Answer: Option (d)
values? 8. The precedence order (from highest to
(a) Logical operator lowest) of arithmetic operators 1 point
(b) Relational operator is
(c) Assignment operator a) %, *, /, +, –
(d) Non of these b) %, +, /, *, –
Answer: Option (b) c) +, -, %, *, /
4. The Operator '&' is used as d) %, +, -, *, /
(a) Logical AND Answer: Option (a)
(b) Bitwise AND 9. What will be the value of variable a?
(c) Logical OR int a = 3.5+4.5;
(d) Bitwise OR (a) a = 0
Answer: Option (b) (b) a = 7
5. Which of the following is a valid relational (c) a = 8
operator? (d) a = 8.0

18 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (c) Answer: Option (d)


10. Which of the following is a valid 14. Which is bit toggling operator below?
assignment operator? (a) & Bitwise AND
(a) += (b) | Bitwise OR
(b) -= (c) ^ Bitwise exclusive OR
(c) *= (d) ~ Bitwise complement
(d) all of above Answer: Option (d)
Answer: Option (d)
11. What will be the value of variable b? 15. Left Shift operation is equivalent to
int a; (a) Division by 2
int b; (b) Multiplying by 2
a=1; (c) Adding 2
b = ++a; (d) Subtrating 2
(a) 1 Answer: Option (b)
(b) 2 16. Which of the following is a symbol for
(c) 3 logical AND operator?
(d) unknown/undefined (a) ||
Answer: Option (b) (b) &
12. Choose the correct statement about left (c) &&
shift Operator << (d) ##
(a) Left shift operator shits individual bits Answer: Option (c)
on the left side 17. Right Shift operation >> is equivalent to _
(b) When shifting left side, Overflow bits (a) Multiplying by 2
are ignored (b) Division by 2
(c) Zeros are filled on the right side (c) Adding 2
(d) all of above (d) Subtracting 2
Answer: Option (d) Answer: Option (b)
13. Choose the correct statement about Right 18. Which of the following is ternary
Shift Operator >> operator?
(a) Right shift operator shifts individual (a) ??
bits on to the right side (b) :?
(b) When shifting bits right side, overflow (c) ?:
bits on the right are ignored or truncated (d) ::
(c) Zeroes are filled on the left side Answer: Option (c)
(d) all of above

19 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

19. What will be the output of following 23. Within a expression, _________
program precedence operators will be evaluated
#include<stdio.h> first
void main() (a) Similar
{ (b) Higher
int x,y=10; (c) Lower
x = y * NULL; (d) None of these
printf("%d",x); Answer: Option (b)
}

(a) error
(b) 0 24. What will the value of variable a?
(c) 10 int a = 10 + 2 * 12 / (3*2) + 5;
(d) garbage value (a) 31
Answer: Option (a) (b) 19
20. Which of following is not a valid (c) 11
assignment expression? (d) 29
(a) y = 22; Answer: Option (b)
(b) s = x; 25. Which of the following correctly shows
(c) y%=6; the hierarchy of arithmetic operation in
(d) z = 5 = 3; C?
Answer: Option (d) (a) /+*-
21. An arithmetic expression without (b) *-/+
paranthesis will be evaluated from left to (c) /*+-
right (d) +-/*
(a) True Answer: Option (c)
(b) False 26. Which of the following are incorrect
Answer: Option (a) statements?
22. In C Programming, the statement a = a+1 1. if(a==7) printf("IncludeHelp");
and a+=1 will produe same result 2. if(7==a) printf("IncludeHelp");
(a) True 3. if(a=7) printf("IncludeHelp");
(b) False 4. if(7=a) printf("IncludeHelp");
Answer: Option (a) a) 1 and 2.
b) 3 only.
c) 4 only.

20 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

d) 2,3 and 4. Answer: Option (d)


Answer: Option (c) 32. If we want to increment the value of sum
27. Which is a correct 'C' expression? by 1. Which of following should be used?
(a) z = (x+y); (a) sum++;
(b) z = [x+y] (b) sum = sum+1;
(c) z = {x+y} (c) sum += 1;
(d) z = {(x+y)}; (d) all of above
Answer: Option (a) Answer: Option (d)
28. Which header file is essential for using 33. Which of following is not a valid
scanf function? assignment expression?
(a) ctype.h (a) y = 22;
(b) string.h (b) s = x;
(c) conio.h (c) y % = 6;
(d) stdio.h (d) z = 5 = 3;
Answer: Option (d) Answer: Option (d)
29. Macro is used to __________________.
(a) Save Memory 34. What is the output?
(b) fast execution void main()
(c) Both a & b {
(d) none of above float a=654.1239;
Answer: Option (b) printf("%0.3f",a);
}
30. Which of the following is ternary
operator? (a) Compiler error
(a) ?? (b) 654.123900
(b) :? (c) 654.123
(c) ?: (d) 654.124
(d) :: Answer: Option (d)
Answer:Option (c) 35. Choose a C formatted Input-Output
31. Which header file is essential for using function below.
scanf() function? (a) printf(), scanf()
(a) ctype.h (b) sprintf(), sscanf()
(b) string.h (c) fprintf(), fscanf()
(c) conio.h (d) All of these
(d) stdio.h Answer: Option (d)

21 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

41. What will be the value of variable a?


36. Multiple variable declarations are float a = 3.5 + 4.5;
separated with (a) a = 8.0
(a) Semicolon (;) (b) a = 8
(b) Colon (;) (c) a = 7
(c) Comma(,) (d) a = 0.0
(d) None of these Answer: Option (a)
Answer: Option (c) 42. What will be the value of variable a?
37. What is the other name of backslash int a = 3.5 + 4.5;
character constants? (a) a = 0
(a) Slash characters (b) a = 7
(b) Space characters (c) a = 8
(c) Escape sequences (d) a = 8.0
(d) None of these Answer: Option (c)
Answer: Option (c) 43. Choose a right statement
38. Which operator is used to compare two int a = 5/2;
values? int b = 5.0/2;
(a) Logical operator int c = 5 / 2.0;
(b) Relational operator int d = 5.0/2.0;
(c) Assignment operator (a) a = 2, b = 2, c = 2, d= 2
(d) None of these (b) a = 2, b = 2.0, c = 2, d= 2.0
Answer: Option (b) (c) a = 2, b = 2.5, c = 2.5, d= 2.5
39. The operator ‘&’ is used as (d) a = 2.5, b = 2.5, c = 2.5, d= 2.5
(a) Logical AND Answer: Option (a)
(b) Bitwise AND 44. Choose a right statement.
(c) Logical OR float a = 5/2;
(d) Bitwise OR float b = 5/2.0;
Answer: Option (b) float c = 5.0/2;
40. Which of the following is a valid float d = 5.0/2.0;
relational operator? (a) a=2.5, b=2.5, c=2.5, d=2.5
(a) = (b) a=2, b=2.5, c=2.5, d=2.5
(b) => (c) a=2.0, b=2.5, c=2.5, d=2.5
(c) == (d) a=2.0, b=2.0, c=2.0, d=2.0
(d) >> Answer: Option (c)
Answer: Option (c) 45. What will the value of variable a?

22 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

int a = 25%10; 49. What will be the value of variable b?


(a) 2.5 int a;
(b) 2 int b;
(c) 5 a=1;
(d) Compiler error b=a++;
Answer: Option (c) (a) 1
(b) 2
46. Which of the following is a valid (c) 3
assignment operator? (d) unknown/undefined
(a) += Answer: Option (a)
(b) -= 50. What will be the value of variable b?
(c) *= int a;
(d) All of these int b;
Answer: Option (d) a=1;
47. What will be the value of variable d? b=++a;
int a = 10, b = 5, c = 5,d; (a) 1
d = b + c == a; (b) 2
(a) Syntax error (c) 3
(b) 1 (d) unknown/undefined
(c) 5 Answer: Option (b)
(d) 10 51. What will be the value of variable z?
Answer: Option (b) int x=3, y=4;
48. What is the output? z = ++x * y++;
void main() (a) 9
{ (b) 12
int a = 10, b = 5, c = 3; (c) 16
b != !a; (d) 20
c = !!a; Answer: Option (c)
printf("%d\t%d", b, c); 52. What will be the output?
} void main()
(a) 5 1 {
(b) 0 3 int a=9, b=9;
(c) 5 3 a=b++;
(d) 1 1 printf("%d %d",a,b);
Answer: Option (a) }

23 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(a) 9,9 (d) Subtracting 2


(b) 10,10 Answer: Option (b)
(c) 9,10 57. Right Shift operation >> is equivalent
(d) 10,9 to___
Answer: Option (c) (a) Multiplying by 2
53. Choose the correct statement about Left (b) Division by 2
Shift Operator << (c) Adding 2
(a) Left shift operator shifts individual (d) Subtracting 2
bits on the left side Answer: Option (b)
(b) When shifting left side, overflow bits 58. What will be the value of variable c?
are ignored int c = 2 ^ 3;
(c) Zeroes are filled on the right side (a) 1
(d) All of these (b) 8
Answer: Option (d) (c) 9
(d) 0
54. Choose the correct statement about Right Answer: Option (a)
Shift Operator >> 59. What will be the value of variable a?
(a) Right shift operator shifts individual int a = 6;
bits on to the right side a = ~a;
(b) When shifting bits right side, overflow (a) -6
bits on the right are ignored or truncated (b) 9
(c) Zeroes are filled on the left side (c) -7
(d) All of these (d) 6
Answer: Option (d) Answer: Option (c)
55. Which is bit toggling operator below? 60. An arithmetic expression without
(a) & Bitwise AND parenthesis will be evaluated from left to
(b) | Bitwise OR right
(c) ^ Bitwise exclusive OR (a) True
(d) ~ Bitwise complement (b) False
Answer: Option (d) Answer: Option (a)
61. In C programming, the statement a=a+1
56. Left Shift operation is equivalent to____ and a+=1 will produce same result
(a) Division by 2 (a) True
(b) Multiplying by 2 (b) False
(c) Adding 2 Answer: Option (a)

24 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(b) 19
62. Within an expression, __________ (c) 11
precedence operators will be evaluated (d) 29
first Answer: Option (b)
(a) Similar 67. Which of the following correctly shows
(b) Higher the hierarchy of arithmetic operations in
(c) Lower C?
(d) None of these (a) / + * -
Answer: Option (b) (b) * - / +
(c) / * + -
63. What will the value of variable a? (d) + - / *
int a = 4 + 4/2*5 + 20; Answer: Option (c)
(a) 40 68. In the following expression guess the
(b) 4 correct order of execution of operator
(c) 34 z=x-y/z*1%2+1
(d) 54 (a) / * % - + =
Answer: Option (c) (b) * / % - + =
64. What will the value of variable a? (c) = / * - % +
int a = 10 + 5 * 2 * 8 / 2 + 4; (d) = / * % - +
(a) 124 Answer: Option (a)
(b) 54 69. What is the output?
(c) 23 void main()
(d) 404 {
Answer: Option (b) int i=0, j=1, k=2, m;
65. What will the value of variable a? m = i++ || j++ || k++;
int a = 4 + 5/2*10 + 5; printf("%d %d %d %d", m, i, j, k);
(a) 29 }
(b) 5 (a) 1 1 2 3
(c) 4 (b) 1 1 2 2
(d) 34 (c) 0 1 2 2
Answer: Option (a) (d) 0 1 2 3
Answer: Option (b)
66. What will the value of variable a?
int a = 10 + 2 * 12 /(3*2) + 5; 70. What is the output?
(a) 31 void main()

25 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

{ b) 2
int x = 1, y = 2; c) 3
printf("%d", x, y); d) 4
} Answer: Option (b)
(a) 1 2
(b) 1
(c) 2
(d) Error 73. Which conversion also called Automatic
Answer: Option (b) Type Conversion?
71. Which of the following statement is a) Implicit Type Conversion
correct? b) Explicit Type Conversion
a) Operator precedence determines c) Both A and B
which operator is performed first d) None of the above
in an expression with more than Answer: Option (a)
one operator with different 74. The following code is an example of?
precedence. Associativity is used double da = 4.5;
when two operators of same double db = 4.6;
precedence appear in an double dc = 4.9;
expression
b) Operator associativity determines //explicitly defined by user
which operator is performed first int result = (int)da + (int)db + (int)dc;
in an expression with more than printf(""result = %d"", result);
one operator with different a) Implicit Type Conversion
associativity. Precedence is used b) Explicit Type Conversion
when two operators of same c) Error
precedence appear in an d) Can not Say
expression Answer: Option (b)
c) Operator precedence and
associativity are same. 75. What will be output for the following
d) None of the above code?
Answer: Option (a) #include<stdio.h>
72. How many type of conversion are there in int main()
c? {
int x = 10;
a) 1 char y = 'a';

26 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

x = x + y; expression, then the corresponding


float z = x + 1.0; operand will also be converted to?
printf(""x = %d, z = %f"", x, z); a) double
return 0; b) long double
} c) int
a) x = 107, z = 108.00 d) float
b) x = 107, z = 108.0000 Answer: Option (b)
c) x = 107, z = 108.000000 79. Which type of conversion is NOT
d) x = 108, z = 108.000000 accepted?
Answer: Option (c) a) From char to int
76. What will be output for the following b) From float to char pointer
code? c) From negative int to char
#include<stdio.h> d) From double to char
int main() Answer: Option (b)
{ 80. Which of the following typecasting is
double x = 1.2; accepted by C?
int sum = (int)x + 1; a) Widening conversions
printf(""sum = %d"", sum); b) Narrowing conversions
return 0; c) Widening & Narrowing conversions
} d) None of the above
a) sum = 2 Answer: Option (c)
b) sum = 1
c) sum = 0 81. When do you need to use type-
d) sum = 3 conversions?
Answer: Option (a)
77. In Implicit type conversion, If an operand a) The value to be stored is beyond the
of long int is present then the other max limit
operand will be converted to ? b) The value to be stored is in a form not
a) unsigned int supported by that data type
b) unsigned long int c) To reduce the memory in use, relevant
c) float to the value
d) long int d) All of the above
Answer: Option (d) Answer: Option (d)
78. In Implicit type conversion, If an operand
of type long double is present in the

27 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

5. Conditional Branching

int x = 1;

1. Decision Control Statement in C can be if (x > 0)

implemented using printf("inside if\n");

a) if else if (x > 0)

b) if-else printf("inside elseif\n");

c) conditional operator }

d) All of the above a) inside if

Correct Option :d. b) inside elseif

2. If block always need to be assoicated with a c)inside if, inside elseif

else block d) compile time error

a) True Answer: a
b) False
5. What will be the output of the following C
Correct Option : a
code?
3. If you have to make decision based on
#include <stdio.h>
multiple choices, which of the following is
int main()
best suited?
{
a) if
int x = 0;
b) if-else
if (x++)
c) if-else-if
printf("true\n");
d) All of the above
else if (x == 1)
Correct Option : c
printf("false\n");
4. What will be the output of the following C
}
code?
a) true
#include <stdio.h>
b) false
int main()
c) compile time error
{

28 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

d) undefined behaviour }
a) false, 0
Answer: b
b) true, 0
6. What will be the output of the following C
c) true, 10
code?
d) compile time error
#include <stdio.h>
int main() Answer: b
{
8. What will be the output of the following C
int x = 0;
code?
if (x == 1)
if (x == 0) #include <stdio.h>
printf("inside if\n");
int main()
else
{
printf("inside else if\n");
else int x = 0;
printf("inside else\n");
if (x == 1)
}
if (x >= 0)
a) inside if
printf("true\n");
b) inside else if
else
c) inside else
printf("false\n");
d) compile time error
}
Answer: c
a) true
7. What will be the output of the following C
b) false
code?
c) Depends on the compiler
#include <stdio.h>
int main() d) No print statement
{
Answer: d
int x = 0;
9. Which of the following is an invalid if-else
if (x == 0)
printf("true, "); statement?
else if (x = 10)
a) if (if (a == 1)){}
printf("false, ");
b) if (func1 (a)){}
printf("%d\n", x);

29 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

c) if (a){} d) Compile time errors during compilation


Answer: d
d) if ((char) a){}
12. What will be the output of the following C
Answer: a
code?
10. What will be the output of the following C #include <stdio.h>
code? int main()
#include <stdio.h> {
int main() if (printf("%d", printf(")))
{ printf("We are Happy");
int a = 1; else if (printf("1"))
if (a--) printf("We are Sad");
printf("True"); }
if (a++) a) 0We are Happy
printf("False"); b) 1We are Happy
} c) 1We are Sad
a) True d) compile time error
b) False Answer: d
c) True False 13. What is the output of C Program?
d) No Output int main()
Answer: a {
11. What will be the output of the following C int k=64;
code? switch(k)
#include <stdio.h> {
int main() case k<64: printf(“SHIP “); break; case
{ k>=64:
int a = 1; printf(“BOAT “);
if (a) break;
printf("All is Well "); default:
printf("I am Well\n"); printf(“PETROL”);
else }
printf("I am not a River\n"); printf(“CHILLY”);
} }
a) Output will be All is Well I am Well a) BOAT CHILLY
b) Output will be I am Well I am not a River b) BOAT PETROL CHILLY
c) Output will be I am Well c) SHIP BOAT CHILLY

30 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

d) Compiler error printf(“JASMINE “);


Answer d continue;
default:
14. What is the output of C Program with printf(“FLOWER “);
switch statement or block? }
int main() printf(“GARDEN”);
{ }
int k=8;
switch(k) a. JASMINE GARDEN
{ b. JASMINE FLOWER GARDEN
case 1==8: c. FLOWER GARDEN
printf(“ROSE “); d. Compiler error
break;
case 1 && 2: Answer d
printf(“JASMINE “); 16. What is the output of C Program with
break; switch statement?
default: int main() {
printf(“FLOWER “); switch(24.5) {
} case 24.5:
printf(“GARDEN”); printf(“SILVER “);
} break;
a) ROSE GARGEN case 25.0:
b) JASMINE GARDEN printf(“GOLD “);
c) FLOWER GARDEN break;
d) Compiler error default:
Answer C printf(“TIN “);
}
15. What is the output of C Program? printf(“COPPER”);
int main() { }
int k=25;
switch(k) { a) SILVER COPPER
case 24: b) TIN COPPER
printf(“ROSE “); c) COPPER
break; d) Compiler error
case 25: Answer d

31 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

17. Choose a correct statement about a C Answer d


Switch Construct. 19. What will be the output of the following C
a) default case is optional inside switch. code? (Assuming that we have entered the
b) break; causes the control to exit the value 1 in the standard input)
switch immediately and avoid fall int main()
down to other CASE statements. {
c) You can not use duplicate CASE int ch;
Constants inside a Switch construct. printf(“enter a value between 1 to 2:”);
d) All the above. scanf(“%d”, &ch);
switch (ch, ch + 1)
Answer d {
18. What will be the output of the following C case 1:
code? (Assuming that we have entered the printf(“1”);
value 2 in the standard input) break;
case 2:
int main() printf(“2”);
{ break;
int ch; }
printf(“enter a value between 1 to 2:”); return 0;
scanf(“%d”, &ch); }
switch (ch)
{ a) 1
case 1: b) 2
printf(“1\n”); c) 3
break; d) Run time error
printf(“hi”); Answer B
default: 20. What will be the output of the following C
printf(“2\n”); code?
} int main()
return 0; {
} int x = 97;
a) 1 switch (x)
b) hi 2 {
c) Run time error case ‘a’:
d) 2 printf(“yes “);

32 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

break; double ch;


case 97: printf("enter a value between 1 to
printf(“no\n”); 2:");
break; scanf("%lf", &ch);
} switch (ch)
{
a) yes case 1:
b) yes no printf("1");
c) Duplicate case value error break;
d) Character case value error case 2:
Answer c printf("2");
21. What will be the output of the following C break;
code? }
int main() return 0;
{ }
printf(“%d “, 1); a) Compile time error
goto l1; b) 1
printf(“%d “, 2); c) 2
l1:goto l2; d) Varies
printf(“%d “, 3); Answer a
l2:printf(“%d “, 4);
return 0;
}

a) 1 4
b) Compilation error
c) 1 2 4
d) 1 3 4
Answer a
22. What will be the output of the following C
code?
(Assuming that we have entered the value 1 in
the standard input)
int main()
{

33 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

6. Iteration and loops


1. Which are not looping structures? b) for
a) For loop c) do-while
b) While loop d) if-else
c) Do...while loop Answer: Option (a)
d) if…else 6. Continue statement
Answer: Option (d) a) Breaks loop and goes to next
statement after loop
2. How many times the following code b) does not break loop but starts new
prints the string “hello” iteration
for(i=1;i<=50;i++) c) exits the program
printf(“Hello”); d) Starts from beginning of program
Answer: Option (b)
a) 1 7. How many times following loop will be
b) 50 executed?
c) Zero void main()

d) None of them {

Answer: Option (b) int i = 32766;

3. The first expression in a for… loop is while (i<= 32767)

a) Step value of loop {

b) Value of the counter variable printf("%d\n",i);

c) Condition statement i = i + 1;

d) None of the above }

Answer: Option (b) }

4. Continue statement used a) 2 times

a) to continue to the next line of code b) 1 times

b) to debug c) infinite times

c) to stop the current iteration and begin d) loop will not be executed

the next iteration from the beginning Answer: Option (a)

d) None of the above 8. The loop which is executed at least once

Answer: Option (c) is


a) while

5. Which among the following is a b) do-while

unconditional control structure. c) for

a) goto d) none of the above

34 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (b) case 7: printf(“seven”);


9. What is the output of the following code: default: printf(“default”);
void main() }
{ }
int i; a) five
for(i=1;i<=10;i++); b) fivesixsevendefault
printf(“%d\n”,i); c) fivesix
} d) None of the above
a) 10 Answer: Option (c)
b) 1 to 10 12. What is the output?
c) 11 void main()
d) None of the above {
Answer: Option (c) int num=10;
10. What is the output of the following code: if(num)
void main() printf("If Executed");
{ else
int i; printf("Else Executed");
for(i=65;i<70;i++) }
printf(“%c,”,i);
} a) If Executed
a) 65,66,67,68,69,70 b) Else Executed
b) a,b,c,d,e, c) Error
c) A,B,C,D,E, d) Blank
d) A,B,C,D,E Answer: Option (a)
Answer: Option (c) 13. What is the output?
11. What is the output of following code: void main()
void main() {
{ if(-100)
int i=5; printf("Negative number");
switch(i) else
{ printf("Positive number");
case 3: printf(“three”); }
case 4: printf(“four”);
case 5: printf(“five”); a) Positive number
case 6: printf(“six”);break; b) Negative number

35 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

c) Error if (x == 5)
d) Random Behavior printf("hi");
Answer: Option (b) else
14. What is the output? printf("no");
void main() }
{
if(1 || 0) (a) hi
printf("C Programming"); (b) hello
else (c) no
printf("learn C"); (d) error
} Answer: Option (a)
(a) learn C 17. What is the output?
(b) Compile Error void main()
(c) C Programming {
(d) Error int x = 5;
Answer: Option (c) if (true);
15. What is the output? printf("hello");
void main() }
{
int x= 5; a) hello
if(x < 1); b) Error
printf("Hello"); c) Blank
printf("Hi"); d) None of these
} Answer: Option (a)
a) Hi 18. What is the output?
b) HelloHi void main()
c) Error {
d) None of these int x = 0;
Answer: Option (b) if (x == 0)
16. What is the output? printf("hi");
void main() else
{ printf("how are u");
int x = 5; printf("hello");
if (x < 1) }
printf("hello");

36 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

a) hi 21. What is the output?


b) how are you void main()
c) hello {
d) hihello int ch;
Answer: Option (d) printf("enter a value between 1 to 2:");
19. If switch case is used, then scanf("%d", &ch);
a) Default case must be present switch (ch)
b) Default case, if used, should not be the {
last case case 1:
c) Default case, if used, should be the last printf("1\n");
case break;
d) None of these printf("Hi");
Answer: Option (c) default:
20. What is the output? printf("2\n");
void main() }
{ }
int ch; //2 is input
printf("enter a value between 1 to 2:"); a) 1
scanf("%d", &ch); b) Hi 2
switch (ch) c) 2
{ d) Error
case 1: Answer: Option (c)
printf("1\n"); 22. What is the output?
default: void main()
printf("2\n"); {
} int x = 0;
} if (x++)
//1 is input printf("true\n");
a) 1 else if (x == 1)
b) 1 2 printf("false\n");
c) 2 }
d) Error a) true
Answer: b) false
Option (b) c) blank
d) Error

37 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (b) printf("Hello");


printf("Hi");
23. What is the output? }
void main() (a) Hi
{ (b) HelloHi
if(-100) (c) Error
printf("Negative number"); (d) None of these
else Answer: Option (b)
printf("Positive number"); 26. What is the output?
} void main()
a) Positive number {
b) Negative number int x = 5;
c) Error if (x < 1)
d) Random Behavior printf("hello");
Answer: Option (b) if (x == 5)
printf("hi");
24. What is the output? else
void main() printf("no");
{ }
if(1 || 0) (a) hi
printf("C Programming"); (b) hello
else (c) no
printf("learn C"); (d) error
} Answer: Option (a)
a) learn C
b) Compile Error 27. What is the output?
c) C Programming void main()
d) Error {
Answer: Option (c) int x = 5;
if (true);
25. What is the output? printf("hello");
void main() }
{ (a) hello
int x= 5; (b) Error
if(x < 1); (c) Blank

38 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(d) None of these printf("1\n");


Answer: default:
Option (a) printf("2\n");
28. What is the output? }
void main() }
{ //1 is input
int x = 0; (a) 1
if (x == 0) (b) 1 2
printf("hi"); (c) 2
else (d) Error
printf("how are u"); Answer: Option (b)
printf("hello"); 31. What is the output?
} void main()
(a) hi {
(b) how are you int ch;
(c) hello printf("enter a value between 1 to 2:");
(d) hihello scanf("%d", &ch);
Answer: Option (d) switch (ch)
29. If switch case is used, then {
a) Default case must be present case 1:
b) Default case, if used, should not be printf("1\n");
the last case break;
c) Default case, if used, should be the printf("Hi");
last case default:
d) None of these printf("2\n");
Answer: Option (c) }
30. What is the output? }
void main() //2 is input
{ (a) 1
int ch; (b) Hi 2
printf("enter a value between 1 to 2:"); (c) 2
scanf("%d", &ch); (d) Error
switch (ch) Answer:
{ Option (c)
case 1: 32. What is the output?

39 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

void main() Answer: Option (b)


{
int x = 0; 36. if the condition is missing in a for loop?
if (x++) a) it is assumed to be present and taken to
printf("true\n"); be false
else if (x == 1) b) it is assumed to be present and taken to
printf("false\n"); the true
} c) it results in a syntax error
(a) true d) execution will be terminated
(b) false Answer: Option (b)
(c) blank
(d) Error 37. Loops in C Language are implemented
Answer: Option (b using?
33. The continue statement cannot be used (a) while Block
with (b) for Block
(a) for (c) do while Block
(b) while (d) All of these
(c) do while Answer: Option (d)
(d) switch 38. What is the output?
Answer: Option (d) void main()
{
34. Which loop is guaranteed to execute at while(true)
least one time? {
(a) for printf("Hello");
(b) while break;
(c) do while }
(d) None of these }
Answer: Option (c)
(a) Hello
35. do-while loop terminates when (b) Hello is printed infinite times
conditional expression returns? (c) Blank
(a) One (d) Error
(b) Zero Answer: Option (d)
(c) Non - zero
(d) None of these 39. What is the output?

40 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

void main() while(a >= 3);


{ {
int a=5; printf("Hello ");
while(a==5) }
{ }
printf("Hello"); (a) Hello
break; (b) Hello is printed infinite times
} (c) Blank
} (d) Error
(a) Hello Answer: Option (c)
(b) Hello is printed infinite times
(c) Blank 42. What is the output?
(d) Error void main()
Answer: Option (a) {
int a=25;
40. What is the output? while(a <= 27)
void main() {
{ printf("%d ", a);
int a=5; a++;
while(a=10) }
{ }
printf("Hello\n"); (a) 25 25 25
break; (b) 25 26 27
} (c) 27 27 27
printf("India"); (d) Error
} Answer: Option (b)
(a) India
(b) Hello India 43. What is the way to suddenly come out of
(c) Hello is printed infinite times or Quit any Loop in C Language?
(d) Error (a) continue;
Answer: Option (b) (b) break;
41. What is the output? (c) stop;
void main() (d) quit;
{ Answer: Option (b)
int a=5;

41 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

7. Functions
1. What is the default return type if it is not 6. A function prototype is used for
specified in function definition? a) Declaring the function logic
(a) void b) Calling the function from the main
(b) int body
(c) float c) Telling the compiler, the kind of
(d) None of these arguments used in the function
Answer: Option (b) d) Telling the user for proper use of
2. Every C Program should contain which syntax while calling the
function? Answer: Option (c)
(a) printf() 7. What is the default return type if it is not
(b) show() specified in function definition?
(c) scanf() a) void
(d) main() b) integer
Answer: Option (d) c) double
d) float
3. Any C Program Answer: Option (b)
(a) Must contain at least one function
(b) Need not contain any function 8. What is the return type of the function
(c) Needs input data with declaration:
(d) None of these int func(char x, float v, double t);
Answer: Option (a) (a) char
4. Function have______ (b) int
(a) Local scope (c) float
(b) Block scope (d) double
(c) File scope Answer: Option (b)
(d) No scope 9. Which of the following is a valid function
Answer: Option (c) call (assuming the function exists)?
5. Which is not a correct function (a) funct;
declaration? (b) funct x, y;
(a) int funct(char x, char y); (c) funct();
(b) double funct(x) (d) int funct();
(c) void funct(); Answer: Option (c)
(d) char x(); 10. In C, function parameters are always
Answer: Option (b) (a) Passed by value

42 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(b) Passed by reference 15. What is the output?


(c) Passed by value result main()
(d) None of these {
Answer: Option (a) int i=abc(10);
printf("%d",--i);
11. What is use of functions? }
(a) Helps to avoid repeating a set of int abc(int i)
statements many times {
(b) Enhances the logical clarity of the return i++;
program }
(c) Makes debugging task easy (a) 10
(d) All of these (b) 9
Answer: Option (d) (c) 11
(d) None of these
12. Arguments passed to a function in C Answer: Option (b)
language are called ____ 16. Which one is the correct statement?
(a) Formal arguments a) The body of a function should have only
(b) Actual arguments one return statement.
(c) Definite arguments b) Function can return only one value in
(d) Ideal arguments call by value environment.
Answer: Option (b) c) Function can return multiple values.
13. Arguments received by a function in C d) None of these
language are called ___ Answer: Option (b)
(a) Formal arguments
(b) Actual arguments 17. Which is the complete function?
(c) Definite arguments (a) int fun();
(d) Ideal arguments (b) int func(int x)
Answer: Option (a) {
14. What is the default return value if it is not return x=x+1;
specified in function definition? }
(a) 0 (c) void fun(int)
(b) -1 {
(c) 1 printf("Hello");
(d) None of these }
Answer: Option (c) (d) void fun(x)

43 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

{ (b) Maximum of two values


printf("Hello"); (c) Maximum of three values
} (d) Any number of values
Answer: Option (b) Answer: Option (a)

18. Choose the correct statement about 21. What is the output?
Functions in C int show()
a) A Function is a group of C {
statements that can be reused any return 10;
number of times. }
b) Every Function has a return type. void main()
c) Every Function may not return a {
value. int a;
d) All the these printf("COUNT=");
Answer: Option (d) a=show();
printf("%d", a);
19. What is the output? }
void show();
void main() (a) COUNT=
{ (b) COUNT=0
show(); (c) COUNT=10
printf("WORLD "); (d) Error
} Answer: Option (c)
void show() 22. What is the output?
{ int show()
printf("HELLO "); {
} return 15;
(a) WORLD HELLO return 35;
(b) HELLO WORLD }
(c) WORLD void main()
(d) Error {
Answer: Option (b) int a;
20. How many values can a C Function return printf("COUNT=");
at a time? a=show();
(a) Only one value printf("%d", a);

44 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

} (c) Pass by value preserves value of


(a) COUNT=15 original variable
(b) COUNT=35 (d) All of these
(c) COUNT=0 Answer: Option (d)
(d) Error 26. What is the output?
Answer: Option (a) int myshow(int b)
23. What is the output? {
int show(int b) printf("%d, ", b);
{ }
printf("%d,",b); void main()
} {
void main() int a=10;
{ myshow(a);
show(5); myshow(&a);
show(10); }
} (a) 10, 10,
(b) 10, Some address
(a) 10,5 (c) 10, Some address (With compiler
(b) 5,10 warning)
(c) 0,0 (d) Error
(d) Error Answer: Option (c)
Answer: Option (b) 27. What is the output?
24. What is the return-type of the function int myshow(int *);
sqrt()? void main()
(a) int {
(b) float int a=10;
(c) double myshow(&a);
(d) depends on the data type of the }
parameter int myshow(int *k)
Answer: Option (c) {
25. Choose correct statements about C printf("%d", *k);
Language pass by value. }
(a) Pass by value copies the variable value (a) Some address
in one more memory location. (b) 10
(b) Pass by value does not use Pointers. (c) Blank

45 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(d) Error 30. Following function belongs to which


Answer: Option (b) category?
28. What is the output? int get10(void)
void myshow(int *); {
void main() return 10;
{ }
int a=10; (a) Function with argument but no return
printf("%d ",a); value
myshow(&a); (b) Function with no argument and no
printf("%d",a); return value
} (c) Function with no argument but returns
void myshow(int *k) a value
{ (d) Function with argument and returns a
*k=20; value
} Answer: Option (c)
(a) 10 10
(b) 20 20 31. Following function belongs to which
(c) 10 20 category?
(d) Error void showNumber(int num)
Answer: Option (c) {
29. Following function belongs to which printf("Number: %d", num);
category? }
void print10() (a) Function with argument but no return
{ value
printf("10"); (b) Function with no argument and no
} return value
(a) Function with argument but no return (c) Function with no argument but returns
value a value
(b) Function with no argument and no (d) Function with argument and returns a
return value value
(c) Function with no argument but returns Answer: Option (a)
a value 32. When function calls itself, it is known as
(d) Function with argument and returns a ______.
value (a) recursion
Answer: Option (b) (b) exit control loop

46 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(c) nested loop (a) printf


(d) user-defined function (b) void
Answer: Option (a) (c) break
33. Recursion is a process in which a function (d) return
calls Answer: Option (d)
(a) itself
(b) another function 38. Recursion is similar to which of the
(c) main() function following?
(d) None of these (a) switch case
Answer: Option (a) (b) loop
34. A recursive function can be replaced with (c) if-else
__ in C (d) if elseif else
(a) for loop Answer:
(b) while loop Option (b)
(c) do while loop 39. How many functions are required to
(d) All of these create a recursive functionality?
Answer: Option (d) (a) One
35. A recursive function is faster than __ loop (b) Two
(a) for loop (c) More than two
(b) while loop (d) None of these
(c) do while loop Answer: Option (a)
(d) None of these
Answer: Option (d) 40. What is the output?
int sum(int);
36. A recursive function without if and else int main()
conditions will always lead to? {
(a) Finite loop int b;
(b) Infinite loop b = sum(4);
(c) Incorrect result printf("%d", b);
(d) Correct result }
Answer: Option (b) int sum(int x)
{
37. What is the C keyword that must be used int k=1;
to get the expected result using if(x<=1)
Recursion? return 1;

47 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

k = x + sum(x-1); (d) Stack


return k; Answer: Option (d)
} 43. What is the output?
(a) 10 main()
(b) 11 {
(c) 12 int n,i;
(d) 15 n=f(6);
Answer: Option (a) printf("%d",n);
}
41. What is the output? f(int x)
int mul(int); {
int main() if(x==2)
{ return 2;
int b; else
b = mul(3); {
printf("%d", b); printf("+");
} f(x-1);
int mul(int x) }
{ }
if(x<=1) (a) ++++2
return 1; (b) +++++2
return (x * mul(x-1)); (c) +++++
} (d) 2
Answer: Option (a)
(a) 2 44. What is the output?
(b) 3 main()
(c) 6 {
(d) 1 int n=10;
Answer: Option (c) int f(int n);
printf("%d",f(n));
42. The data structure used to implement }
recursive function calls _____ int f(int n)
(a) Array {
(b) Linked List if(n>0)
(c) Queue return(n+f(n-2));

48 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

} return number * func(number-1);


(a) 10 }
(b) 80 (a) 12
(c) 30 (b) 24
(d) Infinite loop (c) 1
Answer: Option (c) (d) 0
Answer: Option (b)
45. What is the output? 48. What is the output of func(3,8)?
int main() int func(int a, int b)
{ {
printf("Hello"); if(b==0)
main(); return 0;
return 0; if(b==1)
} return a;
(a) Hello is printed once
(b) Hello infinite number of times return a + func(a,b-1);
(c) Hello is not printed at all }
(d) 0 is returned
Answer: Option (b) (a) 11
46. Which of the following is true? (b) 24
(a) Recursion is always better than q (c) 22
iteration (d) 21
(b) Recursion uses more memory Answer: Option (b)
compared to iteration
(c) Recursion uses less memory compared 49. What is the output of print(12)?
to iteration void print(int n)
(d) Iteration is always better and simpler {
than recursion if (n == 0)
Answer: Option (b) return;
47. What is the output of func(4);? printf("%d", n%2);
int func(int number) print(n/2);
{ }
if(number <= 0) (a) 0011
return 1; (b) 1100
else (c) 1001

49 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(d) 1000
Answer: Option (a)

50. What is the output of sum(8)?


int sum(int n)
{
if (n==0)
return n;
else
return n + sum(n-1);
}
(a) 40
(b) 8
(c) 36
(d) 15
Answer: Option (c)
51. What is the output?
int rec(int num)
{
return (num) ? num%10 + rec(num/10):0;
}
void main()
{
printf("%d",rec(4567));
}
(a) 4
(b) 12
(c) 22
(d) 21
Answer: Option (c)

50 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

8. Array and String


(c) string.h
1. Array index start at (d) stdio.h
(a) 1 Answer: Option (c)
(b) User Defined 6. What is an array in C language?
(c) 0 (a) A group of elements of same data type
(d) None of above (b) An array contains more than one
Answer: Option (c) element
(c) Array elements are stored in memory
2. Every string is terminated by NULL in continuous or contiguous locations
character. How it is represented? (d) All of these
(a) ‘\0’ Answer: Option (d)
(b) NULL
(c) Both a & b 7. How do you initialize an array in C?
(d) none of above (a) int arr[3] = (1,2,3);
Answer: Option (a) (b) int arr(3) = {1,2,3};
3. Which of the following is used as a string (c) int arr[3] = {1,2,3};
termination character? (d) int arr(3) = (1,2,3);
(a) 0 Answer: Option (c)
(b) \0
(c) /0 8. Assuming int is of 4bytes, what is the size
(d) None of these of int arr[15];?
Answer: Option (b) (a) 30
(b) 15
4. The format specifier to accept a string is (c) 4
(a) %c (d) 60
(b) %d Answer: Option (d)
(c) %f 9. The index of the first element in an array is
(d) %s ___
Answer: Option (d) (a) 0
(b) -1
5. Which header file is necessary for strlen() (c) 1
function? (d) 2
(a) conio.h Answer: Option (a)
(b) strings.h

51 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

10. Which of the following statement(s) is/are (b) 6


correct ? (c) 8
int num[7]; num[7]=8; (d) None of these
a) In the first statement 7 specifies a Answer: Option (d)
particular element, whereas in the second 13. What is the right way to initialize array in
statement it specifies a type; C?
b) In the first statement 7 specifies a a) int arr{}={1,2,5,6,9}
particular element, whereas in the second b) int arr[5]={1,2,5,6,9}
statement it specifies the array size. c) int arr{5}={1,2,5,6,9}
c) In the first statement 7 specifies the d) int arr()={1,2,5,6,9}
array size, whereas in the second statement Answer: Option (b)
it specifies a particular element of array. 14. An integer array of size 10 is declared in a
d) In both the statement 7 specifies array C program. The memory location of the
size first byte of the array is 1000. What will be
Answer: Option (c) the location of the 7th element of the array?
(integer takes 2 bytes of memory)
11. What is the output? a) 1014
void main() b) 1012
{ c) 1010
int a[4]={5,6,7,8}; d) 1016
printf("%d",a[1]); Answer: Option (b)
} 15. Which assignment is not valid for integer
(a) 5 arrays in C programming? (arr, arr1 and
(b) 6 arr2 are integer arrays)
(c) 8 a) arr[4]={1,2.5,3,4};
(d) None of these b) arr[]={1,2,3,4}
Answer: Option (b) c) arr1=arr2
d)All are valid assignment
12. What is the output? Answer: Option (c)
void main() 16. Consider the following declaration of a
{ two-dimensional array in C: char
int a[4]={5,6,7,8}; A[100][100]; Assuming that the main
printf("%d",a[4]); memory is byte-addressable and that the
} array is stored starting from memory
(a) 5 address 0, the address of A[40][50] is

52 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

a) 4040 20. What is the output?


b) 4050 void main()
c) 5040 {
d) 5050 int a[3] = {10,12,14};
Answer: Option (b) a[1]=20;
int i=0;
17. In C language the last character of a string while(i<3)
is {
a) \n printf("%d ", a[i]);
b) \0 i++;
c) \b }
d) \t }
Answer: Option (b)
18. Which of the statement is correct? (a) 20 12 14
a) An array may contain more than one (b) 10 20 14
element (c) 10 12 20
b) All elements of array has to be of same (d) Compiler error
data type Answer: Option (b)
c) The size of array has to be declared 21. If we need to store word "INDIA" then
upfront which is correct syntax?
d) All of the above (a) char name[6] = {"I","N","D","I","A"}
Answer: Option (d) (b) char name[6] = {'I','N','D','I','A','\0'}
(c) char name[6] = {'I','N','D','I','A'}
19. What is the output? (d) None of these
void main() Answer: Option (b)
{
int a[] = {1,2,3,4}; 22. What happens when you try to access an
int b[4] = {5,6,7,8}; array variable outside its size?
printf("%d,%d", a[0], b[0]); (a) Compiler error is thrown
} (b) 1 value will be returned
(a) 1,5 (c) 0 value will be returned
(b) 0,0 (d) Some garbage value will be returned
(c) 2,6 Answer:Option (d)
(d) Compiler error 23. How many elements will be declared if an
Answer: Option (a) array declared like below

53 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

int a[7]; {0}


(a) 6 };
(b) 7 printf("%d",a[1][2]);
(c) 8 }
(d) None of these (a) 0
Answer: Option (b) (b) 1
(c) Garbage value
24. How many elements will be declared if an (d) Compiler error
array declared like below Answer: Option (a)
int a[3][4]; 28. What is the output?
(a) 8 int main()
(b) 6 {
(c) 12 int ary[3][2] = {1,2,3,4,5,6};
(d) 9 printf("%d,%d", ary[0][0], ary[2][1]);
Answer: Option (c) }
(a) 2,5
25. Which of the following is correct (b) 1,6
initialization? (c) 1,5
(a) int a[3][3]={{1,2,3},{4,5,6},{7,8,9}}; (d) 2,6
(b) int a[][2] = {{1,2},{3,4}}; Answer: Option (b)
(c) int a[3][3]={1,2,3,4,5,6,7,8,9};
(d) All of these 29. What is the format specifier used to print a
Answer: Option (d) String or Character array in C printf() or
26. Which of the following is a two- scanf () function?
dimensional array? (a) %c
(a) array anarray[20][20]; (b) %s
(b) int anarray[20][20]; (c) %C
(c) int array[20, 20]; (d) %d
(d) char array[20]; Answer: Option (b)
Answer: Option (b) 30. What is the output?
27. What is the output? void main()
void main() {
{ char ary[]="Programming in C";
int a[2][3] = { printf("%s",ary);
{0}, }

54 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(a) Programming in C {
(b) P char str[2];
(c) Programming int i=0;
(d) Compiler error scanf("%s", str);
Answer: Option (a) while(str[i] != '\0')
31. What is the output? {
void main() printf("%c", str[i]); i++;
{ }
char str[25]; }
scanf("%s",str); //Input: INDIA
printf("%s",str);
} (a) IN
//input: Programming in C (b) I
(c) INDIA
(a) Programming in C (d) Compiler error
(b) P Answer: Option (c)
(c) Programming
(d) Compiler error 34. How do you accept a multi-word input in C
Answer: Option (c) language.?
(a) scanf()
32. What is the output? (b) gets()
void main() (c) getc()
{ (d) None of these
char str[]={"C","A","T","\0"}; Answer:
printf("%s",str); Option (b)
} 35. Choose the correct C sentence about
strings.
(a) C (a) printf() is capable of printing a multi-
(b) CAT word string.
(c) CAT\0 (b) puts() is capable of printing a multi-
(d) Compiler error word string.
Answer: Option (d) (c) gets() is capable of accepting a multi-
word string.
33. What is the output? (d) All of these
void main() Answer: Option (d)

55 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

36. If the two strings are identical, then (a) Hello


strcmp() function returns (b) Hello World
(a) -1 (c) WorldHello
(b) 1 (d) None of these
(c) 0 Answer: Option (b)
(d) True 41. Which function will you use to find the last
Answer: Option (c) occurrence of a character in a string?
37. Which function will you choose to merge (a) strnchar()
two words? (b) strrchar()
(a) strcpy() (c) strchar()
(b) strjoin() (d) strrchr()
(c) strcat() Answer: Option (b)
(d) strmerge()
Answer: Option (c) 42. The char data type in C program occupies
38. Which function appends not more than n ______ byte of space in memory.
characters? (a) 1
(a) strcat() (b) 2
(b) strncat() (c) 4
(c) strcon() (d) None of these
(d) None of these Answer: Option (a)
Answer: Option (b)
39. Which of the given options compares at
most n characters of string ch to string s?
(a) strncmp(ch, s, n)
(b) strncmp(s, ch, n)
(c) strcmp(ch, s)
(d) strcmp(s, ch)
Answer: Option (a)
40. What is the output?
void main()
{
char str1[20]="Hello",str2[20]=" World";
printf("%s\n", strcpy(str1, strcat(str1, str2)));
}

56 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

9. Structure and Union


1. Structure can contain elements of the (d) None of these
different data type Answer: Option (b)
(a) True
(b) False 6. What will be the size of the following
Answer: Option (a) structure? (Consider integer occupies – 4
2. Which of the following operator is used to bytes)
select a member of a structure variable struct temp
(a) .(dot) {
(b) ,(comma) int a[10];
(c) : (colon) char p;
(d) ;(semicolon) };
Answer: Option (a)
(a) 5
3. Structure can contain elements of the same (b) 11
data type. (c) 41
(a) True (d) 44
(b) False Answer: Option (c)
Answer: Option (a) 7. Which of the following cannot be a
4. What is a structure in C language? structure member?
(a) A structure is a collection of elements (a) Another structure
that can be of the same data type. (b) Array
(b) A structure is a collection of elements (c) Function
that can be of the different data type. (d) None of these
(c) Elements of a structure are called Answer: Option (c)
members. 8. What is the output?
(d) All of these struct student
Answer: Option (d) {
int no;
5. What is the size of a C structure? char name[20];
(a) C structure is always 128 bytes. };
(b) Size of C structure is the total bytes of void main()
all elements of structure. {
(c) Size of C structure is the size of struct student s;
largest element. s.no = 8;

57 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

printf("%d",s.no); s.no = 8;
} printf("%d",s.no);
(a) 8 }
(b) Compiler error (a) 8
(c) Blank (b) Compiler error
(d) Runtime error (c) Blank
Answer: Option (a) (d) Runtime error
Answer: Option (b)
9. What is the output? 11. Which of the following accesses a variable
struct student in structure b?
{ (a) b->var;
int no = 5; (b) b.var;
char name[20]; (c) b-var;
}; (d) b>var;
void main() Answer: Option (b)
{ 12. Which of the following accesses a variable
struct student s; in structure *b?
s.no = 8; (a) b->var;
printf("%d",s.no); (b) b.var;
} (c) b-var;
(a) 8 (d) b>var;
(b) Compiler error Answer: Option (a)
(c) 5
(d) Runtime error 13. What is the output?
Answer: Option (b) struct pens
{
10. What is the output? int color;
struct student }p1[2];
{ void main()
int no; {
char name[20]; struct pens p2[3];
}; p1[0].color=5;
void main() p1[1].color=9;
{ printf("%d, ",p1[0].color);
student s; printf("%d",p1[1].color);

58 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

} {
(a) 5, 5 printf("%d %d\n", p[0].x, p[1].y);
(b) 5, 9 printf("%d %d\n", p[2].x, p[3].y);
(c) 9, 5 }
(d) Compiler error
Answer: Option (b) (a) 1 2
14. What is the output? 34
struct student (b) 1 0
{ 20
char *name; (c) Compiler Error
}; (d) Blank
struct student s[2]; Answer: Option (a)
void main()
{ 16. The correct syntax to access the member of
s[0].name = "alan"; the ith structure in the array of structures
s[1] = s[0]; is?
printf("%s %s", s[0].name, s[1].name); struct temp
s[1].name = "turing"; {
printf("\n%s %s", s[0].name, int b;
s[1].name); }s[50];
} (a) s.b.[i];
(b) s.[i].b;
(a) alan alan alan turing (c) s.b[i];
(b) alan alan turing turing (d) s[i].b;
(c) alan turing alan turing Answer: Option (d)
(d) None of these 17. What is the output?
Answer: Option (a) void main()
{
15. What is the output? struct book
struct point {
{ int pages;
int x; };
int y; struct book b,*ptr;
} p[] = {1, 2, 3, 4}; b.pages = 100;
int main() ptr = &b;

59 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

printf("%d ", b.pages); a) Yes


printf("\n%d ", ptr->pages); b) No
} c) May Be
d) Can't Say
(a) Compiler error Answer: Option (a)
(b) 100 21. . What is the correct syntax to declare a
100 function foo() which receives an array of
(c) 100 structure in function?
Blank a) void foo(struct *var);
(d) 100 b) void foo(struct *var[]);
Address of b c) void foo(struct var);
Answer: Option (b) d) none of the mentioned
18. Which of the following are themselves a Answer: Option (a)
collection of different 22. Union differs from structure in the
data types? following way
a) String a) All members are used at a time
b) Array b) Only one member can be used at a
c) Character time
d) Structure c) Union cannot have more members
Answer: Option (b) d) Union initialized all members as
19. The size of the following union, where an structure
int occupies 4 bytes of memory is Answer: Option (b)
union demo 23. What is the similarity between a structure,
{ union and enumeration?
float x; a) All of them let you define new
int y; values
char z[10]; b) All of them let you define new data
}; types
a) 8 byte c) All of them let you define new
b) 4 byte pointers
c) 10 byte d) All of them let you define new
d) 18 byte structures
Answer: Option (c) Answer: Option (b)
20. size of union is size of the longest element
in the union

60 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

24. Which of the following share a similarity in a) b->var;


syntax? 1. Union 2. Structure 3. Arrays 4. b) b.var;
Pointers c) b-var;
d) b>var;
a) 3 and 4 Answer: Option (b)
b) 1 and 2 29. Which of the following accesses a variable
c) 2 and 3 in structure *b?
d) All of the above a) b->var;
Answer: Option (b) b) b.var;
c) b-var;
25. Size of a union is determined by size of the. d) b>var;
Answer: Option (a)
a) First member in the union 30. Which of the following is a properly
b) Last member in the union C. Biggest defined struct?
member in the union a) struct {int a;}
c) Sum of the sizes of all members b) struct a_struct {int a;}
d) Biggest member in the union c) struct a_struct int a;
Answer: Option (d) d) struct a_struct {int a;};
Answer: Option (d)
26. Which operator connects the structure 31. Which properly declares a variable of struct
name to its member name? foo?
a) - a) struct foo;
b) . b) struct foo var;
c) Both (b) and (c) c) foo;
d) None of the above d) int foo;
Answer: Option (b) Answer: Option (b)
32. What is the output of this program?
27. How will you free the allocated memory ? #include <stdio.h>
a) remove(var-name); struct test {
b) free(var-name); int x = 0;
c) delete(var-name); char y = 'A';
d) dalloc(var-name); };
Answer: Option (b) int main()
28. Which of the following accesses a variable {
in structure b? struct test t;

61 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

printf("%d, %c", s.x, s.y); c) May Be


return 0; d) Can't Say
} Answer: Option (b)
a) 0
b) Error 37. Pick the incorrect statement with respect to
c) garbage value garbage value enums.
d) None of these a) Two enum symbols cannot have the
Answer: Option (b) same value
33. Enumeration (or enum) is a ______ data b) Only integer constants are allowed in
type in C? enums
a) user defined c) It is not possible to change the value
b) built-in of enum symbols
c) libary d) Enum variables are automatically
d) None Of the above assigned values if no value is
Answer: Option (a) specified
Answer: Option (a)
34. If we do not explicitly assign values to 38. Arithmetic operations are not allowed on
enum names, the compiler by default enumerated constants.
assigns values to ? a) TRUE
a) null b) FALSE
b) -1 c) May Be
c) 0 d) Can't Say
d) Garbage Answer: Option (b)
Answer: Option (c) 39. What is the correct syntax of enum?
35. All enum constants are? a) enum flag{constant1, constant2,
a) Same in their scope constant3, ....... };
b) unique in their scope b) enum flag(constant1, constant2,
c) contain dupicate value in their scope constant3, ....... );
d) None of the above c) enum flag[constant1, constant2,
Answer: Option (b) constant3, ....... ];
36. String handling functions such as strcmp(), d) enumflag{constant1, constant2,
strcpy() etc can be used with enumerated constant3, ....... };
types. Answer: Option (a)
a) TRUE
b) FALSE

62 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

10. Basic Algorithms

1. The worst-case occur in linear search 5. The Average case occurs in the linear
algorithm when ……. search algorithm ……….
a) Item is somewhere in the middle of a. when the item is somewhere in the
the array middle of the array
b) Item is not in the array at all b. when the item is not the array at all
c) Item is the last element in the array c. when the item is the last element in the
d) Item is the last element in the array or array
item is not there at all d. Item is the last element in the array or
item is not there at all
Answer: Option (d)
Answer: Option (a)
2. If the number of records to be sorted is 6. When the Binary search is best applied to
small, then …… sorting can be efficient. an array?
a) Merge a) For very large size array
b) Heap b) When the array is sorted
c) Selection c) When the array elements are mixed
d) Bubble data type
d) When the array is unsorted
Answer: Option (c) Answer: Option (b)
3. The complexity of the sorting algorithm
measures the …… as a function of the 7. Consider the array A[]= {5,4,9,1,3} apply

number n of items to be sorter. the insertion sort to sort the array

a) average time Consider the cost associated with each sort


b) running time is 25 rupees, what is the total cost of the
c) average-case complexity insertion sort for sorting the entire array?
d) case-complexity
a) 25
Answer: Option (b)
b) 50
c) 75
4. Which of the following is not a limitation
d) 100
of binary search algorithm?
a) must use a sorted array Answer: Option (c)
b) requirement of sorted array is 8. In ……………, search start at the
expensive when a lot of insertion and beginning of the list and check every
deletions are needed
element in the list.
c) there must be a mechanism to access
middle element directly a) Linear search
d) binary search algorithm is not efficient b) Binary search
when the data elements more than c) Hash search
1500. d) Binary tree search
Answer: Option (d)
Answer: Option (a)

63 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

9. Binary search algorithm cannot be applied b) O(logn)


to … c) O(n2)
d) O(n logn)
a) sorted linked list
Answer: Option (c)
b) sorted binary trees
c) sorted linear array
d) pointer array 14. State True or False for internal sorting
algorithms.
Answer: Option (a)
i) Internal sorting are applied when the entire
collection if data to be sorted is small enough
10. Complexity of linear search algorithm is that the sorting can take place within main
……… memory.
a) O(n)
ii) The time required to read or write is
b) O(logn)
considered to be significant in evaluating the
c) O(n2)
performance of internal sorting.
d) O(n logn)
a) i-True, ii-True
Answer: Option (a)
b) i-True, ii-False
11. Which of the following is a disadvantage of c) i-False, ii-True
linear search? d) i-False, ii-False
Answer: Option (b)
a) Requires more space

b) Greater time complexities compared to


other searching algorithms 15. The complexity of merge sort algorithm is
a) O(n)
c) Not easy to understand
b) O(logn)
d) All of the mentioned c) O(n2)
d) O(n logn)
Answer: Option (b) Answer: Option (d)

12. Sorting algorithm can be characterized as 16. ………. is putting an element in the

…… appropriate place in a sorted list yields a

a) Simple algorithm which require the larger sorted order list.


order of n2 comparisons to sort n a. Insertion
items. b. Extraction
b) Sophisticated algorithms that require c. Selection
the O(nlog2n) comparisons to sort d. Distribution
items. Answer: Option (a)
c) Both of the above
d) None of the above 17. …………order is the best possible for array
Answer: Option (c) sorting algorithm which sorts n item.
13. The complexity of bubble sort algorithm is a) O(n logn)
b) O(n2)
…..
c) O(n+logn)
a) O(n)
64 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

d) O(logn) a) Bubble sort


Answer: Option (c) b) Insertion sort
c) Merge sort
18. ……… is rearranging pairs of elements d) Selection sort

which are out of order, until no such pairs Answer: Option (d)
remain.
a) Insertion 23. Which of the following is not the required
b) Exchange condition for a binary search algorithm?
c) Selection a) The list must be sorted
d) Distribution
b) There should be direct access to the
Answer: Option (b)
middle element in any sublist
19. ………… is the method used by card c) There must be a mechanism to delete
sorter. and/or insert elements in the list.
d) Number values should only be present
a) Radix sort
b) Insertion Answer: Option (c)
c) Heap
d) Quick
24. Partition and exchange sort is ……..
Answer: Option (a) a) quick sort
b) tree sort
c) heap sort
20. Which of the following sorting algorithm is d) bubble sort

of divide and conquer type? Answer: Option (a)


a) Bubble sort
b) Insertion sort
c) Merge sort
d) Selection sort
Answer: Option (c)
21. …….. sorting algorithm is frequently used
when n is small where n is total number of
elements.
a) Heap
b) Insertion
c) Bubble
d) Quick
Answer: Option (b)

22. Which of the following sorting algorithm


is of priority queue sorting type?

65 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

11. Pointers

1. If ptr is a pointer to int, having value 4. Pointer variable is declared using preceding
ptr=100. After ptr++, what is the value of _________ sign
ptr? a) %
(a)100
b) &
(b)101
c) *
(c)102
d) ^
(d)103
Answer: Option (c)
Answer: Option (c)
5. Address stored in the pointer variable is of
2. A Pointer is? type ________
(a)A keyword used to create variables. (a) Integer

(b)A variable that stores address of an (b) Floating

instruction. (c) Hexadecimal

(c)A variable that stores address of other (d) Character

variable. Answer: Option (a)

(d)All of above 6. Consider the 32 bit compiler. We need to


store address of integer variable to integer
Answer: Option (c)
pointer. What will be the size of integer
pointer?
3. A pointer value refers to (a) 6 Bytes
(a)A float value
(b) 2 Bytes
(b)An integer constant
(c) 4 Bytes
(c)Any valid address in memory
(d) 10 Bytes
(d)None
Answer: Option (b)
Answer: Option (c)
7. In order to fetch the address of the variable
we write preceding _________ sign before
variable name.
(a) Percent (%)

(b) Ampersand (&)

66 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(c) Comma (,) Answer: Option (b)

(d) Asterik (*) 11. What is the output?


void main()
Answer: Option (b)
{
8. "&" is called as ___________ in pointer
concept int* pc, c;
(a) Conditional operator
c = 5;
(b) Logical operator
pc = &c;
(c) Address operator
c = 1;
(d) None of these
printf("%d, %d", c,*pc);
Answer: Option (c)
}
9. "*" is called as __________
(a) 1, 1
(a) Value at operator
(b) 1, 5
(b) Scope resolution operator
(c) 5, 1
(c) Address operator
(d) Error
(d) None of these
Answer: Option (a)
Answer: Option (a)
12. What is the output?
10. What is the output?
void main()
void main()
{
{
int a = 5;
int *pc, c;
int *ptr ;
c = 5;
ptr = &a;
pc = &c;
*ptr = *ptr * 3;
printf("%d", *pc);
printf("%d", a);
}
}
(a) Address of c
(a) Some address
(b) 5
(b) 5
(c) Address of pc
(c) 15
(d) Error

67 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(d) Error Answer: Option (a)

Answer: Option (c) 15. What is an array base address in c


language?
13. What is the output?
(a) Base address is the address of 0th index
void main()
element
{
(b) An array b[] base address is &b[0]
int* pc, c;
(c) An array b[] base address can be printed
c = 5;
with printf("%d", b);
pc = &c;
(d) All of these
*pc = 1;
Answer: Option (d)
printf("%d, %d", c,*pc);
16. What is meaning of the following
}
statement?
(a) 1, 1
int *ptr[20];
(b) 1, 5
(a) Integer array to integer pointers having
(c) 5, 1
size 20
(d) Error
(b) Array of integer pointers of size 20
Answer: Option (a)
(c) Integer array of size 20 pointing to an
14. What is the output?
integer pointer
void main()
(d) None of these
{
17. Answer: Option (b)
int i = 3, *j, k;
What is the output?
j = &i;
void main()
printf("%d\n", i * *j * i + *j);
{
}
char str[] = "peace";
(a) 30
char *s = str;
(b) 27
printf("%s\n", s+3);
(c) 9
}
(d) 3
(a) Peace

68 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(b) eace int (*p)[5]; means

(c) ace (a)p is dimension array of size 5, of pointers

(d) ce to integers

Answer: Option (b) (b) p is a pointer to a 5 elements integer array

18. What is the output? (c) Incorrect declaration


void main()
(d) None of these
{
Answer: Option (b)
int a[3] = {20,30,40};
21. What is the output?
printf("%d", *(a+1)); void main()
{
}
int arr[5] = {1,5,9,13,18};
(a)20
int *p = &arr[2];
(b)30 int *q = &arr[4];
printf("%d",*q-*p);
(c)40
}
(d)Compiler error

Answer: Option (b) (a) 8


(b) 9
19. What is the output?
(c) -8
void main()
(d) -9
{
Answer: Option (b)
int a[4] = {5,6,7,8}; 22. What is the output?
void main()
printf("%d %d", *(a+2), a[1]);
{
}
int arr[5] = {1,5,9,13,18};
(a) 8 6 int *p = &arr[1];
int *q = &arr[4];
(b) 7 6
printf("%d",q-p);
(c) 6 6
}
(d) Compiler error (a) 6
(b) 12
Answer: Option (b)
(c) 3
20. The declaration
(d) 13

69 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (c) Answer:Option (b)


23. What is the output? 25. What is the output?
void fun(int *ptr) void test(int *a, int *b)
{ {
*ptr = 30; a = b;
} *a = 15;
void main() }
{ int main()
int y = 20; {
fun(&y); int x = 10, y = 20;
printf("%d", y); test(&x, &y);
} printf("%d, %d", x, y);
(a) 20 }
(b) 30 (a) 15, 15
(c) Compiler error (b) 10, 15
(d) Runtime error (c) 10, 20
Answer: Option (b) (d) 15, 20
24. What is the output? Answer: Option (b)
void test(int * , int *);
void main() 26. Difference between calloc() and malloc()
{ (a) calloc() takes a single argument while
int a = 5 , b = 6; malloc() needs two arguments
test(&a,&b); (b) malloc() takes a single argument while
printf("%d, %d",a,b); calloc() needs two arguments
} (c) malloc() initializes the allocated
void test(int *p, int *q) memory to ZERO
{ (d) calloc() initializes the allocated
*p = *p * *q; memory to NULL
*q = *p / *q; Answer: Option (b)
*p = *p / *q;
} 27. Which function reallocates memory?
(a) 30, 5 (a) realloc
(b) 6, 5 (b) calloc
(c) 5, 6 (c) malloc
(d) None of these (d) None of these

70 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

Answer: Option (a)


28. Which of the following header files must 32. Suppose we have a one-dimensional array,
necessarily be included to use dynamic named ‘x’, which contains 10 integers.
memory allocation functions? Which of the following is the correct way
(a) stdlib.h to allocate memory dynamically to the
(b) stdio.h array ‘x’ using malloc()?
(c) memory.h (a) x=(int*)malloc(10);
(d) dos.h (b) x=(int*)malloc(10,sizeof(int));
Answer: Option (a) (c) x=malloc(int 10,sizeof(int));
(d) x=(int*)malloc(10*sizeof(int));
29. What is correct about malloc() function? Answer: Option (d)
(a) Allocates the memory of requested
size. 33. What is the output?
(b) Returns the pointer to the first byte of void main()
allocated space. {
(c) Returns the pointer to the first byte of int *p;
allocated space. p = (int *)malloc(20); /* Assume p has
(d) All of these address of 1314 */
Answer: Option (d) printf("%d", p);
30. The number of arguments taken as input }
which allocating memory dynamically
using malloc() is _______ (a) 1314
(a) 0 (b) 1316
(b) 1 (c) NULL
(c) 2 (d) void
(d) 3 Answer: Option (a)
Answer: Option (b) 34. What is the output?
31. Which of the following statement is correct void main()
for the malloc() function in C? {
(a) int* malloc(int); int *p;
(b) char* malloc(char); p = (int *)malloc(20);
(c) unsigned int* malloc(unsigned int); printf("%d", sizeof(p));
(d) void* malloc(size_t); }
Answer: (a) 4
Option (d) (b) 2

71 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(c) 8 38. When the pointer is NULL, then the


(d) Garbage value function realloc is equivalent to the
Answer: Option (b) function _____
35. Which function is used to delete the (a) malloc()
allocated memory space? (b) calloc()
(a) dealloc() (c) free()
(b) free() (d) alloc()
(c) both a and b Answer: Option (a)
(d) delete() 39. If malloc() and calloc() are not type casted,
Answer: the default return type is _____
Option (b) (a) void*
36. What is the output if it is executed on a 32 (b) void**
bit processor? (c) int*
void main() (d) char*
{ Answer: Option (a)
int *p; 40. Which of the following functions allocates
p = (int *)malloc(20); multiple blocks of memory, each block of
printf("%d", sizeof(p)); the same size?
} (a) malloc()
(a) 2 (b) realloc()
(b) 4 (c) calloc()
(c) 8 (d) free()
(d) Garbage value Answer: Option (c)
Answer: Option (a) 41. What if functionality if realloc() function?
(a) Change the location of memory
37. What is correct about calloc() function? allocated by malloc() or calloc().
(a) Allocates the space for elements of an (b) Reallocates memory deleted by free()
array. function.
(b) Initializes the elements to zero. (c) It is used to modify the size of the
(c) If space is insufficient returns a NULL previously allocated memory space.
pointer. (d) None of these
(d) All of these Answer: Option (c)
Answer: Option (d) 42. What is the output?
void main()
{

72 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

char *p = calloc(100, 1);


p = "welcome";
printf("%s", p);
}
(a) Address of p
(b) welcome
(c) Garbage value
(d) Error
Answer: Option (b)
43. What is the output?
void main()
{
int *ptr;
ptr = (int *)calloc(1,sizeof(int));
*ptr = 10;
printf("%d\n",*ptr);
}

(a) 0
(b) -1
(c) 10
(d) NULL
Answer: Option (c)
44. What is the output?
void main()
{
int *ptr;
ptr = (int *)calloc(1,sizeof(int));
printf("%d\n",*ptr);
}
(a) 0
(b) -1
(c) Error
(d) Null
Answer: Option (a)

73 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

12. File management


1. When fopen() fails to open a file it returns (a) A character string containing the name
(a) NULL of the file & the second argument is the mode.
(b) 1 (b) A character string containing the name
(c) -1 of the user & the second argument is the mode.
(d) None of above (c) A character string containing file
Answer: Option (a) pointer & the second argument is the mode.
2. File manipulation functions in C are (d) None of these
available in which header file? Answer: Option (a)
(a) streams.h
(b) stdio.h 6. Which one of the following is correct
(c) stdlib.h syntax for opening a file.
(d) files.h (a) FILE *fopen(const *filename, const
Answer: Option (b) char *mode)
(b) FILE *fopen(const *filename)
3. Which of the following true about FILE *fp (c) FILE *open(const *filename, const
(a) FILE is a keyword in C for char *mode)
representing files and fp is a variable of (d) FILE open(const*filename)
FILE type. Answer: Option (a)
(b) FILE is a structure and fp is a pointer
to the structure of FILE type 7. What is the function of the mode ‘ w+’?
(c) FILE is a stream (a) Create text file for writing, discard
(d) FILE is a buffered stream previous contents if any
Answer: Option (b) (b) Create text file for update, discard
previous contents if any
4. Which of the following file open mode (c) Create text file for writing, do not
argument is used to truncate? discard previous contents if any
(a) a (d) Create text file for update, do not
(b) w discard previous contents if any
(c) r Answer: Option (b)
(d) t 8. If the mode includes 'b' after the initial
Answer: Option (b) letter, what does it indicates?
(a) text file
5. The first and second arguments of fopen() (b) big text file
are (c) binary file

74 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(d) bit file (a) fscanf() can read from standard input
Answer: Option (c) whereas scanf() specifies a stream
9. getc() returns EOF when from which to read
(a) end of files is reached (b) fscanf() can specifies a stream from
(b) When getc() fails to read a character which to read whereas scanf() can read
(c) Both A and B only from standard input
(d) None of these (c) fscanf() and scanf() has no difference
Answer: Option (c) in their functions
(d) fscanf() and scanf() can read from
10. A data of the file is stored in___ specified stream
(a) RAM Answer: Option (b)
(b) ROM 14. What does the following C statement
(c) Hard disk mean?
(d) None of these char *gets(char *s)
Answer: (a) Reads the next input line into the array
Option (c) (b) Writes the line into the array s.
(c) Reads the next input character into the
11. Select a function which is used to write a array s.
string to a file______ (d) Write a character into the array.
(a) pits() Answer: Option (a)
(b) putc()
(c) fputs() 15. Which function will return the current file
(d) fgets() position for stream?
Answer: (a) fgetpos()
Option (c) (b) fseek()
(c) ftell()
12. fflush(NULL) flushes all ________ (d) fsetpos()
(a) input streams Answer: Option (c)
(b) output streams
(c) previous contents 16. Choose a correct statement about C file
(d) appended text mode "a".
Answer: Option (b) FILE *fp;
fp=fopen("abc.txt","a");
13. Choose the right statement for fscanf() and
scanf()

75 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

(a) "a" is for append operation. You can printf("%d",i);


append or add new content to the existing return 0;
contents. }
(b) If file is not found, new file is created. a) 27
(c) You cannot write read file contents. b) x is not declared
(d) All of these c) No output
Answer: Option (d) d) Garbage value
17. What is the C function used to move Answer: Option (a)
current pointer to the beginning of file?
(a) rev() 20. What is the output of this program?
(b) rewind() #include <stdio.h>
(c) rew() #include <stdlib.h>
(d) begin() #define square(x) x*x
Answer: Option (b) int main()
18. What is the output of this program? {
#include <stdio.h> int i;
#define int char i = 27/square(3);
main() printf("%d",i);
{ return 0;
int i=50; }
printf ("sizeof (i) =%d", sizeof (i)); a) 9
} b) Compilation error
a) 2 c) 3
b) 4 d) 27
c) 8 Answer: Option (d)
d) 1
Answer: Option (d) 21. What is the output of this program?

19. What is the output of this program? #include <stdio.h>


#include <stdio.h> #define i 5
#define x 3 int main()
int main() {
{ #define i 10
int i; printf("%d",i);
i = x*x*x; return 0;

76 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

} Answer: Option (c)


a) Compilation error
b) 10 24. What is the output of this program?
c) 5 #include <stdio.h>
d) Runtime error #define p 17;
Answer: Option (b) int main()
{
22. What is the output of this program? printf("%d",p);
return 0;
#include <stdio.h> }
#define clrscr() 17 a) Garbage value
int main() b) Runtime error
{ c) 17
clrscr(); d) Compilation error
printf("%d",clrscr()); Answer: Option (d)
return 0;
} 25. Which statment is true about the given code
a) Compilation error ?
b) Runtime error #include <stdio.h>
c) 17 enum colors {lets,find,course};
d) none of the above int main()
{
Answer: Option (c) printf("%d %d %d",course,lets,find);
return 0;
23. What is the output of this program? }
#include <stdio.h> a) 312
int main() b) 012
{ c) 201
printf("%d",30); d) 102
return 0; Answer: Option (c)
}
a) Runtime Error 26. What is the Error of this program?
b) Garbage value #include <stdio.h>
c) Compilation error #define CONDITION(x)
d) 30 printf("letsfindcourse");

77 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

int main() b) a message from programmer to the


{ microprocessor
CONDITION(0); c) a message from programmer to the
return 0; preprocessor
} d) a message from compiler to the linker
a) letsfindcourse
b) Compilation error Answer: Option (c)
c) Runtime error
d) None of the above 29. Which of the following are correctly
Answer: Option (b) formed #define statements?

27. How will you free the memory allocated by a) #define INCH PER FEET 12
the following program? b) #define SQR(X) (X *X);
c) #define SQR(X) X*X
#include <stdio.h> d) #define SQR(X) (X*X)
#define CONDITION(x)
printf("letsfindcourse"); Answer: Option (d)
int main()
{ 30. A macro must always be written in capital
CONDITION(0); letters.
return 0;
} a) TRUE
a) Runtime Error b) May Be
b) letsfindcourse c) FALSE
c) Compilation error d) Can't Say
d) None of the above Answer: Option (c)
Answer: Option (b)
31. A macro should always be accommodated
in a single line.
a) TRUE
b) May Be
28. What is a preprocessor directive c) FALSE
a) a message from compiler to the d) Can't Say
programmer Answer: Option (a)

78 University Academy
PROGRAMMING FOR PROBLEM SOLVING 2020-21

32. After preprocessing when the program is a) Before compilation


sent for compilation the macros are b) During execution
removed from the expanded source code. c) After Compilation
a) TRUE d) None of the above
b) FALSE Answer: Option (a)
c) Can be true or false
d) Can't Say
Answer: Option (a)

33. Macros with arguments are not allowed.


a) TRUE
b) May Be
c) FALSE
d) Can't Say
Answer: Option (b)

34. Tn a macro call the control is passed to the


macro.
a) TRUE
b) FALSE
c) May Be
d) Can't Say
Answer: Option (b)

35. All macro substitutions in a program are


done?
a) Before compilation of the program.
b) During execution
c) After compilation
d) None of the above
Answer: Option (a)

36. In a program the statement: #include


"filename" is replaced by the contents of
the file "filename"?

79 University Academy

You might also like