0% found this document useful (0 votes)
44 views7 pages

FinalCElec Tec Ans

A c data structure exam
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)
44 views7 pages

FinalCElec Tec Ans

A c data structure exam
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/ 7

‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬

‫جامعة السودان للعلوم و التكنولوجيا‬


‫ مدرسة الهندسة الكهربائية‬-‫كلية الهندسة‬
‫م‬2019/2018 ‫)الدورة الثا ي( للعام الدرا‬-‫اﻻمتحانات الفصلية‬

Date: 30/12/2020 Time Allowed: 3 Hours


Title of course: Programming Language Year: Second Technology
Student’s Name: ……..…………………………Student’s No.: …………………
Answer All Question
Question No(1):
1) Choose a correct answer
1) Find a correct C Keyword below.
a) work b) case c) constant d) permanent
2) Every C Program should contain which function.?
a) printf() b) scanf() c) main() d) show()
3) Which of the following is not true about pre-processor directives
a) The begin with a hash symbol b) They are processed by a pre-processor
c) They form an integral part of the code d) They have to end with a semicolon
4) Single line comments explaining code would be preceded with:
a) // b) *// c) /* d) /**
5) Which one is not a correct variable type in C++?
a) float b) real c) int d) double
6) An Identifier can start with.?
a) Any character that can be typed on a keyboard b) Alphabet
c) Underscore ( _ ) sign d) Option B & Option C
7) Identify wrong C Keywords below.
a) auto, double, int, default b) break, else, long, switch
c) char, extern, intern, return (intern not a keyword) d) case, float, register, void
8) Which operation is used as Logical 'AND'
a) Operator & b) Operator || c) Operator && d) Operator +
9) Which of the following is the default return value of functions in C++?
a) float b) int c) char d) void
10) What is the value of this statement?
10/2 * 6 / 2 +(5 -3 *(2 - 1))
a) 13 b) 17 c) 33 d) 35
11) Value of Z after the execute the following code?
int z,x=5,y= -10,a=4,b=2;
z = x++- --y*b/a;
a) 5 b) 6 c) 9 d) 10 e) 11

1
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
12) What will be the values of x, m and n after the execution of the following statements?
int x, m, n;
m =10; n=15;
x = ++m + n++;
a)x=25, m=10, n=15 b)x=26, m=11, n=16
c)x=27, m=11, n=16 d)x=27, m=10, n=15
13) What the value of the variable result?
int x=5,y=2;
int result;
result=x % y;
a) 1 b) 2.5 c) 7 d) 10
14) What is the output?
int x=1;
if (x > 3)
{ if (x > 4)
printf("Third");
else
printf("Fifth");
}
else
if (x < 2)
if (x != 0)
printf("Computer");
printf("Mathematic");
a) Computer Mathematic b) Mathematic c) Fifth Mathematic d) Third Mathematic
15) What is the output of C Program with Switch Statement.?
int a=5;
switch(a)
{ case 0: printf("0 ");
case 3: printf("3 ");
case 5: printf("5 ");
default: printf("RABBIT ");
}
a=10;
switch(a)
{ case 0: printf("0 ");
case 3: printf("3 ");
case 5: printf("5 ");
default: printf("RABBIT "); break;
}
a) 5 RABBIT RABBIT b) 0 3 5 RABBIT 0 3 5 RABBIT
c) 0 3 5 RABBIT RABBIT d) 3 5 RABBIT RABBIT

2
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
16) The break statement causes an exit
a) From the innermost loop only b) Only from the innermost switch
c) From all loops & switch d) From the innermost loop or switch
17) A continue statement causes execution to skip to
a) The return 0; statement b) The first statement after the loop
c) The statement following the continue statement d) The next iteration of the loop
18) What’s wrong ?(x=4 && y=5)?(a=5) ;(b=6);
a) The question mark should by an equal sign b) There are too many variables in statement
c)The first semicolon should be a colon d) The conditional operator is only used with up strings
19) Which looping process checks the test condition at the end of the loop
a) for b) while c) do-while
d) no looping process checks the test condition at the end the end
20) Expression C=i++ causes
a) Value of i assigned to C and then i incremented by 1
b) i to be incremented by 1 and then the value of i assigned to C
c) The value of i assigned to C d) i to be incremented by 1
21) In a group of nested loops,which loop is executed the most number of times ?
a) the outermost loop b) all loops are executed the same number of times
c) the innermost loop d) cannot be determined without knowing the size of the loops
22) if there is more than one statement in th block of a for loop,which is the following must be
placed at the beginning and the ending of the loop block
a) parentheses() b) braces{} c) brackets[] d) arrows <>
23) Which looping process is best used when the number of iteration is known ?
a) for b) while c) do-while d) all looping processes require that the iterations be known
24) In a C language ‘3’ represents
a) A number b) An integer c) A character d) A word
25) What is the output of the code above?
int values[3];
values[0] = 5; values[1] = values[0]*2; values[2] = values[1] * 2;
printf(“%d”,values[1]);
a) 5 b) 10 c) 20 d) None
26) Arguments passed to a function in C language are called ___ arguments.
a) Definite arguments b) Ideal arguments c) Formal arguments d) Actual arguments
27) Find a C Storage Class below.
a) static b) auto c) register & extern d) All the above
28) Which among the following is a Local Variable.?
a) static b) auto c) register d) extern
29) What is the output of a C program with functions.?
void show();
3
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
void main()
{ show();
printf("RAINBOW ");
}
void show()
{ printf("COLOURS ");
}
a) RAINBOW COLOURS b) COLOURS RAINBOW
(‫مهما كان موقعها‬main ‫)التنفيذ يبدأ من الدالة الرئيسية‬
c) COLOURS d) Compiler error
30) Which function definition will run correctly?
a) int sum(int a, int b) b) int sum(int a, int b) c) int sum(a, b) d) Both (a) and (b)
return (a + b); {return (a + b);} return (a + b);

Question No(3):
1) Rewrite the following program using switch statement?
if(mark = = 90)
printf("Excellent \n ");
else if(mark = =80) switch(mark)
printf("Very Good \n "); { case 90: printf(“Excellent \n”);
else if(mark = =70) break;
printf("Good\n "); case 80:printf(“Very Good \n”);
else break;
printf("Good Luck\n "); case 70:printf(“Good\n”);
} break;
} default:
printf(“Good Luck\n”);
}

2) Convert the following do-while loop to


for loop? int digit;
int digit =1 for(digit=1; digit <= 5; digit ++)
do {
{ printf("%d ", digit);
printf("%d”,digit); }
digit ++;
} while(digit<5);

4
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬

Question No(3):
1) Fill in the blank:
a) A variable known only within the function in which it’s defined is called a local
b) Storage-class specifier register is store a variable in registers.
c) A function that call itself Recursive
d) Allows the compiler to check the number, types and order of the arguments passed to a function
Function Prototype

2) Differentiate between:
a) Local & Global variable
Local variable is a variable declared and used in a function that declared .
Global variable :
Variables that are alive and active throughout the entire program .Can be accessed by any
function in the program.Declared outside the function
b) Formal (‫ &)الشكلي‬Actual(‫ )الفعلي‬Variable
Formal variable is a variable used in a function definition and Actual Variable is a
variable used in function calling

c) Pass(call) by Value and Reference Parameters?


Pass(call) by Value Copy of argument passed to function
Changes in function do not effect original
Use when function does not need to modify argument(Avoids accidental changes)
Call by reference
Passes original argument
Changes in function effect original
Only used with trusted functions

Question No(4):
1) Write a program that print the following shape output
*
**
***
****
*****
int i,j;
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
printf("* ");
printf("\n");
}

5
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
2) Create an array and initialize its elements with the numbers
2, 56, 78, 6
int a[4]={2,56,78,6};
Print the array in question(2) on the screen
printf("Enter array elements \n");
for(i=0;i<=3;i++)
printf("%d",a[i]);

3) Write a full program that receive from the user the radius of a circle in a main function,then
calls a function circleArea with that radius to calculate the area of that circle and returned
them to calling function
‫ والتي تقوم بحساب مساحة الدائرة‬circleArea‫)برنامج يستقبل من المستخدم نصف قطر الدائرة ويقوم باستدعاء الدالة‬
.( main‫ ثم طباعة مساحة الدائرة داخل ال‬main ‫وارجاعها الي الدالة الرئيسية‬
float recArea(float r)
{ float result;
float pi=3.14;
result=pi*r*r;
return result;
}
void main( )
{ float radius ,area;
printf("Enter radius of circle:");
scanf("%f",&radius);
area= recCircle(radius);
printf("The area of a circle:%f",area);
}

Question No(5):
1) What is the output of the following programs
1) 5) int m = 7;
int x= 90 - 15 / 3 + 3 * 2 – 1; void fun1( )
printf("%d \n",x); 90 { int m = 30;
2) m++;
int x = 22,y=15; printf("%d\n",m);
x = (x>y) ? (x+y) : (x-y); }
printf("%d \n",x); 37

6
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
3) void fun2( )
int count; { static int m = 50;
for(count =1; count <7;count++) m++;
{ printf("%d\n",m);
if(count == 5) }
{ printf("Condition true \n"); void fun3( )
break; { m =m* 10;
} printf("%d\n",m);}
else if(count==3) void main()
continue; { int m = 5;
printf("%d ",count); printf("%d\n",m);
} { int m= 10;
1 2 4 Condition true printf("%d\n",m);
}
4) printf("%d\n",m);
void my_function(int x) { fun1();
x = 50; fun2();
printf("Value of x =%d\n",x); fun3();
} fun1();
main() { fun2();
int x = 10; fun3();
printf("Value of x in main =%d\n",x); printf("%d\n",m);
my_function(x); }
printf("Value of x in main =%d\n",x); 5
} 10
5
Value of x in main =10 31
Value of x =50 51
Value of x in main =10 70
31
52
700
5

With My best Wishes


‫حَ ى ُف ى ال َقل فﻶ يَ قى لَه إﻵ جَ ل مَﺎ‬..‫َ أج َلَ و ه َ ا‬ ُ ‫ل اﻻن ﺎن في هَ هـ ال َ آة م لَ قل ال صآص ت ه العَ َ آت ل‬

You might also like