0% found this document useful (0 votes)
26 views

ERTAQE CS Final Revision

This document contains 25 multiple choice questions about C programming concepts. The questions cover topics like data types, operators, functions, loops, conditional statements, and more. For each question, the user is asked to select the correct answer from 4 options provided along with an optional explanation for the answer. This quiz tests a learner's understanding of fundamental C programming concepts.

Uploaded by

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

ERTAQE CS Final Revision

This document contains 25 multiple choice questions about C programming concepts. The questions cover topics like data types, operators, functions, loops, conditional statements, and more. For each question, the user is asked to select the correct answer from 4 options provided along with an optional explanation for the answer. This quiz tests a learner's understanding of fundamental C programming concepts.

Uploaded by

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

Intro.

To CS (Final Revision)

“MCQ”

Q 1 - Special symbol permitted with in the identifier name.

A -$ B-@ C- _ D-.
Answer : C
Explanation : The only permitted special symbol is under score (_) in the identifier.

Q 2 - What is the output of the following program?

#include<stdio.h>

int main();

void main(){

printf("Okay");

A - Okay B - No output C - Compile error. We cannot declare main() function.


D - Compile error. Mismatch in declaration & definition.

Answer : D
Explanation: It’s compile error as the declaration of main() mismatches with the
definition.

Q 3 - In C programming language, a function prototype is a declaration of the function that


just specifies the function’s interface (function's name, argument types and return type) and
extracts the body of the function. By defining the function, we get to know what action a
particular function is going to perform.

A – True B - False
Answer : A
Explanation: The function body shall associate a specific task, hence representing the
action.
Q 4 - The correct order of evaluation for the expression “z = x + y * z / 4 % 2 – 1”

A-*/%=+- B-/*%-+=

C--+=*%/ D-*/%+-=

Answer : D
Explanation : * / % holds highest priority than + - . All with left to right associativity.

Q5- Prototype of a function means ____


A- Name of Function B- Output of Function
C- Declaration of Function D- Input of Function
Answer : C

Q6- Name the loop that executes at least once.


A- For B - If C – While D– do-while
Answer : D

Q7- By default a real number is treated as a.


A - float B - double C - long double D – int
Answer : B
Explanation: The function body shall associate a specific task, hence representing the
action.
Q8- When we mention the prototype of a function?
A - Defining B - Declaring C - Prototyping D – Calling
Answer : B
Explanation: A function prototype in C or C++ is a declaration of a function that omits
the function body but does specify the function's name, argument types and return type.
While a function definition specifies what a function does, a function prototype can be
thought of as specifying its interface.

Q9- Which of the following correctly shows the hierarchy of arithmetic operations in
C?
A) / + * - B) * - / + C) + - / * D) / * + -

Answer : D
Explanation: Simply called as BODMAS (Bracket of Division, Multiplication, Addition and
Subtraction).
How Do I Remember ? BODMAS !
 B - Brackets first
 O - Orders (ie Powers and Square Roots, etc.)
 DM - Division and Multiplication (left-to-right)
 AS - Addition and Subtraction (left-to-right)

Q 10 - Which of the following is the correct order if calling functions in the below code?
a = f1(23, 14) * f2(12/4) + f3();
A - f1, f2, f3 B - f3, f2, f1 C - Order may vary from compiler to compiler

D – None of above
Answer : C
Explanation: Here, Multiplication will happen before the addition, but in which order the
functions would be called is undefined. In an arithmetic expression the parenthesis tells the
compiler which operands go with which operators but do not force the compiler to evaluate
everything within the parenthesis first.

Q 11 - The keyword used to transfer control from a function back to the calling
function is
A - switch B - goto C - go back D – return
Answer : D
Explanation: The keyword return is used to transfer control from a function back to the
calling function.
Example:

#include<stdio.h>
int add(int, int); /* Function prototype */

int main(){
int a = 4, b = 3, c;
c = add(a, b);
printf("c = %d\n", c);
return 0;
}
int add(int a, int b){
/* returns the value and control back to main() function */
return (a+b);
}

Output: c = 7

Q 12 How many times the program will print "ERTAQE " ?


#include<stdio.h>

int main()
{
printf("ERTAQE");
main();
return 0;
}

A - Infinite times B - 32767 times C - 65535 times D – Till stack overflows


Answer : D
Explanation: A call stack or function stack is used for several related purposes,
but the main reason for having one is to keep track of the point to which each active
subroutine should return control when it finishes executing.
A stack overflow occurs when too much memory is used on the call stack.
Here function main() is called repeatedly and its return address is stored in the stack. After
stack memory is full. It shows stack overflow error.
Q 13 How many times the program will print "ERTAQE" ?
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++){
if(x < 5)
continue;
else
break;
printf("ERTAQE");
}
return 0;
}

A - Infinite times B - 11 times C - 0 times D – 10 times


Answer : C
Explanation: Debugging the code by yourself ^_^

Q 14 - How many times the while loop will get executed ?

#include<stdio.h>
int main(){
int j=1;
while(j <= 255){
printf("%c %d\n", j, j);
j++;
}
return 0;
}

A - Infinite times B - 255 times C - 256 times D – 254 times


Answer : B
Explanation: The while(j <= 255) loop will get executed 255 times.

Q 15 - Which of the following cannot be checked in a switch-case statement?


A - Character B - Integer C - Float D – enum

Answer : B
Explanation: The switch/case statement in the c language is defined by the language
specification to use an int value, so you cannot use a float value.

switch( expression )
{
case constant-expression1: statements 1;
case constant-expression2: statements 2;
...
default : statements 4;
}

The value of the 'expression' in a switch-case statement must be an integer, char,


short, long. Float and double are not allowed.

Q 16 - What are the different types of real data type in C ?


A - float, double B - short int, double, long int

C - float, double, long double D – double, long int, float


Answer : C
Explanation: The floating-point data types are called real data types.
Hence float, double, and long double are real data types.

Q 17 - The binary equivalent of 5.375 is


A - 101.101110111 B - 101.011

C - 101011 D – None of above


Answer : B

Q 18 - To print out a and b given below, which of the following printf() statement will you use?
A - printf("%f %lf", a, b); B - printf("%Lf %f", a, b);
C - printf("%Lf %Lf", a, b); D – double, long int, float
Answer : A
Explanation:
To print a float value, %f is used as format specifier.
To print a double value, %lf is used as format specifier.
Therefore, the answer is printf("%f %lf", a, b);

Q 19 - Which of the following are unary operators in C?


1. !
2. sizeof
3. ~
4. &&
A - 1, 2 B - 1, 3 C - 2, 4 D – 1, 2, 3
Answer : D
Explanation : An operation with only one operand is called unary operation.
Unary operators:
! Logical NOT operator.
~ bitwise NOT operator.
sizeof Size-of operator.
&& Logical AND is a logical operator.
Therefore, 1, 2, 3 are unary operators.

Q 20 - In which order do the following gets evaluated


A - Relational B - Arithmetic C - Logical D – Assignment
Answer : A
Explanation:
2. Arithmetic operators: *, /, %, +, -
1. Relational operators: >, <, >=, <=, ==, !=
3. Logical operators : !, &&, ||
4. Assignment operators: =

Q 21 - Which of the following is the correct usage of conditional operators used in C?


A - a>b ? c=30 : c=40; B - a>b ? c=30;
C - max = a>b ? a>c ? a:c:b > c ? b:c D – return (a>b) ? (a:b)
Answer : C
Explanation: Option A: assignment statements are always return in parenthesis in the
case of conditional operator. It should be a>b? (c=30):(c=40);
Option B: it is syntactically wrong.
Option D: syntactically wrong, it should be return(a>b ? a:b);
Option C: it uses nested conditional operator, this is logic for finding greatest number out of
three numbers.
Q 22 - What will be the output of the following C code?
1. #include <stdio.h>
2. int main(){
3. void foo();
4. printf("1 ");
5. foo();
6. }
7. void foo(){
8. printf("2 ");
9. }
A -12 B - Compile time error C-1212 D – Depends on the compiler
Answer : A
Q 23 - What will be the output of the following C code?

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

A- Compile time error as foo is local to main B- 12


C-21 D – Compile time error due to declaration of functions inside main
Answer : B

Q 24 - What will be the output of the following C code?

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

A –22 B - 2
C - Compile time error D – Depends on the compiler
Answer : D
Q 25 - What will be the output of the following C code?

1. #include <stdio.h>
2. void foo();
3. int main(){
4. void foo();
5. foo();
6. return 0;
7. }
8. void foo(){
9. printf("2 ");
10. }
A – Compile time error B - 2
C - Depends on the compiler D – Depends on the standard
Answer : B

Q 26 - What will be the output of the following C code?


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

A –2 B - Compile time error


C - Depends on the compiler D – Depends on the standard
Answer : A
Q 27 - What will be the output of the following C code?
1. #include <stdio.h>
2. void foo();
3. int main(){
4. void foo(int);
5. foo();
6. return 0;
7. }
8. void foo(){
9. printf("2 ");
10. }

A –2 B - Compile time error


C - Depends on the compiler D – Depends on the standard
Answer : B
Q 28 - What will be the output of the following C code?
1. #include <stdio.h>
2. void m(){
3. printf("hi");
4. }
5. void main(){
6. m();
7. }

A –2 B - Compile time error


C - Depends on the compiler D – Depends on the standard
Answer : A

Q 29 - What will be the output of the following C code?


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

A – hi B - Compile time error


C - Nothing D – Varies
Answer : B

Q 30 - Which function definition will run correctly?


a)
int sum(int a, int b)
return (a + b);
b)
int sum(int a, int b) {return (a + b);}
c)
int sum(a, b)
return (a + b);
d) none of the mentioned.

Answer : B
Q 31 - What will be the output of the following C code?
1. #include <stdio.h>
2. int foo();
3. int main(){
4. int i = foo();
5. }
6. foo(){
7. printf("2 ");
8. return 2;
9. }

A –2 B - Compile time error


C - Depends on the compiler D – Depends on the standard
Answer : A

Q 32 - What will be the output of the following C code?


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

A –2 B - Compile time error


C - Depends on the compiler D – Depends on the standard
Answer : B
Exercises (C How to program book)

1.1 a) Computers process data under the control of sequences of instructions called computer
programs.

b) High Level languages are most convenient to the programmer for writing programs quickly
and easily.

c) The only language a computer can directly understand is that computer’s machine language.

d) The programs that translate high-level language programs into machine language are called
compilers.

e) With open-source development, individuals and companies contribute their efforts in


developing, maintaining and evolving software in exchange for the right to use that software for
their own purposes, typically at no charge.

f) C is widely known as the development language of the UNIX operating system.

1.2 a) C programs are normally typed into a computer using a (n) editor program.

b) In a C system, a (n) preprocessor program automatically executes before the translation phase
begins.

c) The two most common kinds of preprocessor directives are including other files in the file to
be compiled and performing various text replacements.

d) The linker program combines the output of the compiler with various library functions to
produce an executable image.

e) The loader program transfers the executable image from disk to memory.

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

Exercises
1.4 Categorize each of the following items as either Hardware or Software:

a) CPU or ALU (Hardware)

b) C or C++ compiler (Software)

d) C or C++ preprocessor (Software)


e) Input unit (Hardware) ‫وحدات االدخال زي الماوس والكيبورد‬

f) An editor program or IDE (Software)

Self-Review Exercises

2.1 a) Every C program begins execution at the function main.

b) Every function’s body begins with left brace { and ends with right brace {.

c) Every statement ends with a (n) semicolon;

d) The printf standard library function displays information on the screen.

e) The escape sequence \n represents the new line character, which causes the cursor to
position to the beginning of the next line on the screen.

f) The scanf standard Library function is used to obtain data from the keyboard.

g) The conversion specifier %d is used in a scanfformat control string to indicate that an


integer will be input and in a printf format control string to indicate that an integer will be
output.

h) Whenever a new value is placed in a memory location, that value overrides the
previous value in that location. This process is said to be destructive.

i) When a value is read from a memory location, the value in that location is preserved;
this process is said to be nondestructive.

j) The if statement is used to make decisions.

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

2.2 State whether each of the following is true or false. If false, explain why.
) ‫( صح وخطأ مع التعليل إذا كانت خطأ‬

a) Function printf always begins printing at the beginning of a new line.


Answer: False. Function printf always begins printing where the cursor is positioned, and this
may be anywhere on a line of the screen.
b) Comments cause the computer to display the text after // on the screen when the
program is executed.
Answer: False. Comments do not cause any action to be performed when the program is
executed. They’re used to document programs and improve their readability.

c) The escape sequence \n when used in a printf format control string causes the cursor to
position to the beginning of the next line on the screen.
Answer: True.

d) All variables must be defined before they’re used.


Answer: True.

e) All variables must be given a type when they’re defined


Answer: True.

f) C considers the variables number and NuMbEr to be identical.


Answer: False. C is case sensitive, so these variables are unique.

g) Definitions can appear anywhere in the body of a function.


Answer: False. A variable’s definition must appear before its first use in the code.

h) All arguments following the format control string in a printffunction must be preceded
by an ampersand (&).
Answer: False. Arguments in a printffunction ordinarily should not be preceded by an
ampersand. Arguments following the format control string in a scanffunction ordinarily
should be preceded by an ampersand.

i) The remainder operator (%) can be used only with integer operands.
Answer: True.

j) The arithmetic operators *, /, %, + and ‫ ــ‬all have the same level of precedence.
Answer: False. The operators *, / and % are on the same level of precedence, and the
operators + and ‫ ــ‬are on a lower level of precedence.

k) A program that prints three lines of output must contain three printf statements.
Answer: False. A printf statement with multiple \n escape sequences can print several
lines.
“From Previous Midterm”
1) Software in computer enhances the capabilities of the hardware machine.

2) The long-term, the high-capacity “warehousing” section. Programs or data not actively
being used by the other units normally are placed on it, is called secondary storage unite.

3) A web page is located using a Uniform Resource Locator.(URL)

4) The \a escape character can be used to beep from speaker in C.

5) The || OR operator has the lowest priority.

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

2.6 Identify and correct the errors in each of the following statements
) ‫الخطأ أو التصحيح باللون األحمر( اوجد الخطأ وصححه‬

a) Printf ("The value is %d\n", &number);


Answer: printf ("The value is %d\n", number);

b) Scanf ("%d%d", &number1, number2);


Answer: scanf ("%d%d", &number1, &number2);

c) if (c<7) ;{
Printf ("C is less than 7\n”);
}
Answer:
if (c <7 ){
Printf ("C is less than 7\n”);
}

d) If(c=>7) {
Printf (“C is greater than or equal to 7\n”);
}

Answer:
if (c>=7) {
printf (“C is greater than or equal to 7\n”);
}
Exercises
2.7 Identify and correct the errors in each of the following statements. (Note: They may be more
than one error per statement.)

‫األحمر ( اوجد الخطأ وصححه ) الخطأ أوالتصحيح باللون‬

a) Scanf(“d", value);
Answer: scanf (“%d", &value);
b) Printf(“The product of %d and %d is %d"\n, x, y );
Answer: Printf (“The product of %d and %d is %d"\n, x, y, result );

c) firstNumber + secondNumber = sumOfNumbers


Answer: firstNumber + secondNumber = sumOfNumbers;

d) */ Program to determine the largest of three integers/*


Answer: /*Program to determine the largest of three integers */

e) Scanf (“%d", anInteger);


Answer: Scanf (“%d", &anInteger);

f) Printf(“Remainder of %d divided by %d is\n", x, y, x % y);


Answer: printf (“Remainder of %d divided by %d is %d \n", x, y, x % y);

g) if (x=y)
Printf(“%d is equal to %d\n", x, y);
Answer:
if (x == y)
Printf (“%d is equal to %d\n", x, y);

h) Printf (“The value you entered is: %d\n, &value);


Answer:
Printf (“The value you entered is: %d\n, value);

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬
2.8 Fill in the blanks in each of the following:

a) Comments are used to document a program and improve its readability.

b) The function used to display information on the screen is printf, puts.

c) A C statement that makes a decision is if function.

d) Calculations are normally performed by assignment statements.

e) The scanf function inputs values from the keyboard.

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

2.10 State which of the following are true and which are false. If false, explain your
answer.
‫صح وخطأ وعلل إذا كانت الجملة خطأ‬

a) C operators are evaluated from left to right.


Answer: True.

b) The following are all valid variable names: _under_bar_, m928134, t5, j7, her_sales,
his_account_total, a, b, c, z, z2.
Answer: True.

c) The statement printf ("a = 5 ;"); is a typical example of an assignment statement.


Answer: False, printf ("a = 5") ;

e) the following are all invalid variable names: 3g, 87, 67h2, h22, 2h.
Answer: False, not all h22 is true.

d) A valid arithmetic expression containing no parentheses is evaluated from left to right.


Answer: True, but maybe there are operators like *, % and /which have a high level of
precedence, therefore +, - and = have a lower level of precedence.
2.11 Answer the following questions :

a) What arithmetic operations are on the same level of precedence as multiplication ?


Answer: / and %

b) When parentheses are nested, which set of parentheses is evaluated first in an


arithmetic expression ?
Answer: the operators in the innermost pair of parentheses are applied first.
Likethe set of parentheses in red color: (4*2+3-2(6/2)%2) =11.

c) A location in the computer’s memory that may contain different values at various times
throughout the execution of a program is called a variable.

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

2.12 What, if anything, prints when each of the following statements is performed ? If
nothing prints, then answer “Nothing.” Assume x = 2 and y = 3.

A) Printf (“%d", x); >>>> 2


b) Printf (“%d", x + x); >>>> 4
c) Printf (“x = “); >>>> x=
d) Printf (“x = %d", x); >>>> x=2
e) Printf (“%d = %d", x + y, y + x); >>>> 2=2
f) Z = x + y; >>>> Nothing
g) Scanf (“%d%d", &x, &y); >>>> Nothing
h) // printf (“x + y = %d", x + y); >>>> Nothing
i) Printf (“\n”); >>>> Nothing

‫ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ‬

Pseudocode is an artificial and informal language that helps you develop algorithms.

Algorithms is the solution to any computing problem involves executing a series of actions in a
specificorder.

Flowchart is a type of diagram that represents an algorithm, workflow or process.

<3 😉 ‫باألخالق_والعلم_نرتقي‬#

You might also like