β˜‘ MCQ PRACTICE

Programming for Problem Solving Unit 1

Practice objective questions for quick revision and examination preparation. Try answering each question before revealing the answer.

πŸ“š Programming for Problem Solving
πŸ“– Unit 1
🎯 MCQs

Programming for Problem Solving - Unit-1

1
C language has been developed by
AKen Thompson
BDennis Ritchie
CPeter Norton
DMartin Richards
Correct AnswerDennis Ritchie
2
C programs are converted into machine language with the help of
AAssembler
BCompiler
CInterpreter
DAll the above
Correct AnswerCompiler
3
In C Programming a variable cannot start with
AAn alphabet
BA number
CA special symbol other than underscore
DBoth (B) & (C) above
Correct AnswerBoth (B) & (C) above
4
Which of the following statements is false
AEach new C instruction has to be written on a separate line
BUsually all C statements are entered in small case letters
CBlank spaces may be inserted between two words in a C statement
DBlank spaces cannot be inserted within a variable name
Correct AnswerEach new C instruction has to be written on a separate line
5
Which of the following is a primary role of a compiler?
AExecute code
BTranslate source code into machine code
CDebug programs
DStore data
Correct AnswerTranslate source code into machine code
6
In C programming, what is the data type that can store decimal numbers?
Aint
Bchar
Cfloat
Dbool
Correct Answerfloat
7
What type of error occurs when the syntax of the code is incorrect?
ALogical error
BRuntime error
CSyntax error
DCompilation error
Correct AnswerSyntax error
8
Which of the following storage classes in C has a scope limited to the block in which it is defined?
Aextern
Bstatic
Cregister
Dauto
Correct Answerauto
9
What does the 'printf' function primarily do?
AReads user input
BOutputs formatted data to the console
CCompiles code
DStores data
Correct AnswerOutputs formatted data to the console
10
Which operator is used for bitwise AND operation in C?
A&&
B&
C||
D|
Correct Answer&
11
In a switch-case statement, what is the purpose of the 'default' case?
ATo handle all cases
BTo terminate the program
CTo handle unspecified cases
DTo execute the first case
Correct AnswerTo handle unspecified cases
12
Which loop in C will always execute at least once?
Afor loop
Bwhile loop
Cdo-while loop
Dnone of the above
Correct Answerdo-while loop
13
What is the correct way to declare an integer variable in C?
Aint 1number;
Bint number;
Cnumber int;
Dint number[];
Correct Answerint number;
14
Which of the following is not a valid C data type?
Aint
Bfloat
Cstring
Dchar
Correct Answerstring
15
What does the 'goto' statement do in C?
AJump to a specific line of code
BEnd the program
CLoop through an array
DConditional branching
Correct AnswerJump to a specific line of code
16
Which command line argument is typically used to pass input to a C program?
A-input
Bargv
Cargc
Dinput
Correct Answerargv
17
In C, what will be the output of printf("%d", 5 + 3 * 2);
A16
B11
C8
D10
Correct Answer11
18
Which of the following correctly describes a prime number?
AA number that has more than two factors
BA number that can be divided only by 1 and itself
CA negative number
DAny integer greater than 0
Correct AnswerA number that can be divided evenly by 1 and itself
19
What is the output of the following code snippet? printf("%c", 'A' + 1);
AA
BB
CC
D66
Correct AnswerB
20
In a flowchart, what does the diamond shape represent?
AStart/End
BProcess
CInput/Output
DDecision
Correct AnswerDecision
21
Which operator is used for bitwise OR operation in C?
A&
B|
C^
D~
Correct Answer|
22
What type of loop would you use when the number of iterations is not known beforehand?
Afor loop
Bwhile loop
Cdo-while loop
Dforeach loop
Correct Answerdo-while loop
23
What is the purpose of 'extern' storage class?
ATo define a variable in the local scope
BTo make a variable available across multiple files
CTo create a static variable
DTo allocate dynamic memory
Correct AnswerTo make a variable available across multiple files
24
Which of the following is a correct declaration of a float variable in C?
Afloat number = 5.5;
Bfloat number(5.5);
Cfloat number : 5.5;
Dfloat number[5.5];
Correct Answerfloat number = 5.5;
25
In C, how do you indicate a comment that spans multiple lines?
A// comment
B/* comment */
C# comment
D** comment **
Correct Answer/* comment */
26
What does the 'sizeof' operator do in C?
AReturns the size of a variable in bits
BReturns the size of a variable in bytes
CAllocates memory
DConverts data types
Correct AnswerReturns the size of a variable in bytes
27
Which of the following is an example of a logical error?
AMissing semicolon
BInfinite loop
CIncorrect output despite correct syntax
DUsing undeclared variable
Correct AnswerIncorrect output despite correct syntax
28
What is the result of the expression 5 & 3 in C?
A8
B2
C0
D1
Correct Answer1
29
Which of the following is an example of explicit type casting in C?
Aint x = 5.6;
Bfloat y = (float)7;
Cchar z = 'A' + 32;
Ddouble w = 3 / 2;
Correct Answerfloat y = (float)7;
30
A user wants to calculate the area of a rectangle with a length of 5 and a width of 10. Which algorithm would best describe the solution?
AArea = Length + Width
BArea = Length Γ— Width
CArea = Length / Width
DArea = Length - Width
Correct AnswerArea = Length Γ— Width
31
You are designing an app to determine if a user’s age qualifies for a senior citizen discount. What conditional statement would you use?
Aif age > 60
Bif age < 60
Cif age == 60
Dif age >= 60
Correct Answerif age >= 60
32
A program needs to find the maximum score from a list of exam scores. Which storage class would be best for the maximum score variable within the function?
Astatic
Bextern
Cauto
Dregister
Correct Answerauto
33
You want to print a message in a C program indicating successful completion of a task. Which output function would you use?
Aprintf("Task completed successfully.");
Bscanf("Task completed successfully.");
Cinput("Task completed successfully.");
Doutput("Task completed successfully.");
Correct Answerprintf("Task completed successfully.");
34
When compiling a program, what is generated that the operating system can execute directly?
ASource code
BPseudocode
CObject code
DFlowchart
Correct AnswerObject code
35
A grocery store wants to calculate discounts for products. If the original price is $50 and the discount is 20%, what should be the new price calculated using C?
ANew Price = 50 - (50 * 0.2)
BNew Price = 50 + (50 * 0.2)
CNew Price = 50 / 0.2
DNew Price = 50 * 0.2
Correct AnswerNew Price = 50 - (50 * 0.2)
36
If you want to iterate through a list of customer names using a loop, which loop structure would be most appropriate if you know the number of names?
Awhile loop
Bfor loop
Cdo-while loop
Dgoto loop
Correct Answerfor loop
37
Which loop in C is used when you want the loop to execute at least once?
Afor loop
Bwhile loop
Cdo-while loop
Dif-else loop
Correct Answerdo-while loop
38
A program needs to read a user's input for their favorite fruit. Which function would you use?
Aoutput()
Bprintf()
Cscanf()
Dread()
Correct Answerscanf()
39
To track a global variable used across multiple files in a project, which storage class should you choose?
Astatic
Bauto
Cextern
Dregister
Correct Answerextern
40
If you want to store a list of ages, which data type would be most appropriate in C?
Afloat
Bchar
Cint
Ddouble
Correct Answerint
41
Which bitwise operation would you use to toggle a specific bit in a number?
AAND
BOR
CXOR
DNOT
Correct AnswerXOR
42
To find the minimum number in a list of temperatures, which pseudocode step is essential?
AInitialize a variable to store the maximum temperature.
BCompare each temperature with the current minimum.
CCalculate the average temperature.
DSort the list of temperatures.
Correct AnswerCompare each temperature with the current minimum.
43
Which type of error occurs when the program runs but produces incorrect results?
ACompilation error
BSyntax error
CRuntime error
DLogical error
Correct AnswerLogical error
44
In a program to determine eligibility for voting, which conditional structure would you use to check if a person is over 18 years old?
Aswitch-case
Bif-else
Cfor loop
Ddo-while
Correct Answerif-else
45
A function needs to output a formatted date, such as "Today is: 2024-10-16". Which C function is best for this?
Ascanf()
Bprint()
Cprintf()
Doutput()
Correct Answerprintf()
46
You are writing a program to find out how many times a user can afford a $10 movie ticket with $100. Which operator would you use?
A+
B-
C/
D*
Correct Answer/
47
To create a simple menu for user choices, which structure would be most appropriate?
Aif-else
Bswitch-case
Cfor loop
Dwhile loop
Correct Answerswitch-case
48
Which statement correctly identifies the output of printf("%d", 10 >> 1);?
A5
B10
C20
D0
Correct Answer5
49
When reading a floating-point number from user input, which format specifier should you use in scanf?
A%d
B%f
C%c
D%s
Correct Answer%f
50
In a project that requires a calculation for the area of a triangle, what formula would you represent in pseudocode?
AArea = base + height
BArea = 0.5 * base * height
CArea = base / height
DArea = base - height
Correct AnswerArea = 0.5 * base * height
51
Which logical operator would you use to check if a number is both even and greater than zero?
AOR
BAND
CNOT
DXOR
Correct AnswerAND

Fill in the Blanks

52A ______________ is a software tool that translates high-level programming code into machine code or an intermediate code.
Correct AnswerCompiler
53After compilation, the result is typically an ______________ file, which can be executed directly by the computer.
Correct AnswerExecutable
54The first step in program execution is the ______________ phase, where the operating system loads the program into memory.
Correct AnswerLoading
55A ______________ is a step-by-step set of instructions for solving a specific problem.
Correct AnswerAlgorithm
56Flowcharts are a graphical way to represent algorithms using ______________ and ______________.
Correct AnswerSymbols, arrows
57In a flowchart, a rectangle is used to represent a ______________.
Correct AnswerProcess
58______is a programming paradigm that promotes the use of functions or procedures to break a program into smaller, manageable parts.
Correct AnswerStructured Programming
59A variable's ____________ defines the type of data it can hold.
Correct Answerdata type
60The size of the char data type in C is ____________ bytes.
Correct Answer1
61A ____________ error occurs when the code violates the rules of the programming language.
Correct Answersyntax
62Logical errors can lead to incorrect program ____________.
Correct Answerbehavior
63In the expression 5 + 3 * 2, the multiplication operator * has higher ____________ than the addition operator +.
Correct Answerprecedence
64In C, the result of integer division, such as 7 / 3, is ____________.
Correct Answer2
65The ____________ storage class specifies that a variable's value is retained between function calls.
Correct Answerstatic
66The ____________ storage class is used to declare global variables.
Correct Answerextern
67Explicit type conversion is also known as ____________.
Correct Answercasting
← Back to All MCQs