ERTAQE CS Final Revision
ERTAQE CS Final Revision
To CS (Final Revision)
“MCQ”
A -$ B-@ C- _ D-.
Answer : C
Explanation : The only permitted special symbol is under score (_) in the identifier.
#include<stdio.h>
int main();
void main(){
printf("Okay");
Answer : D
Explanation: It’s compile error as the declaration of main() mismatches with the
definition.
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.
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
int main()
{
printf("ERTAQE");
main();
return 0;
}
#include<stdio.h>
int main(){
int j=1;
while(j <= 255){
printf("%c %d\n", j, j);
j++;
}
return 0;
}
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;
}
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);
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. }
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
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. }
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.
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:
Self-Review Exercises
b) Every function’s body begins with left brace { and ends with right brace {.
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.
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.
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
2.2 State whether each of the following is true or false. If false, explain why.
) ( صح وخطأ مع التعليل إذا كانت خطأ
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.
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.
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
2.6 Identify and correct the errors in each of the following statements
) الخطأ أو التصحيح باللون األحمر( اوجد الخطأ وصححه
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 );
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);
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
2.8 Fill in the blanks in each of the following:
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
2.10 State which of the following are true and which are false. If false, explain your
answer.
صح وخطأ وعلل إذا كانت الجملة خطأ
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.
e) the following are all invalid variable names: 3g, 87, 67h2, h22, 2h.
Answer: False, not all h22 is true.
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.
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
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.
<3 😉 باألخالق_والعلم_نرتقي#