0% found this document useful (0 votes)
2K views8 pages

FinalElex 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)
2K views8 pages

FinalElex 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/ 8

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

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


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

Date: 4/1/2021 Time Allowed: 3 Hours


The title of course: C language Year: Second
Student’s Name: ……..…………………………Student’s No.: …………………
Answer All Question
Question No(1):
1) Choose a correct answer
1) Find a correct C Keyword.
a) Float b) Int c) Long d) double
2) Which of the following is not a valid variable name declaration?
a) int__a3; b) int__3a; c) int__A3; d) None of them
3) What characters are allowed in a C function name identifier?
a) Alphabets, Numbers, %, $, _ b) Alphabets, Numbers, Underscore ( _ )
c) Alphabets, Numbers, dollar $ d) Alphabets, Numbers, %
4) Identify wrong C Keywords below.
a) switch, long, if, else b) return, for, case, do
c) struct, construct, signed, unsigned d) static, while, break, main
5) All keywords in C are in ____________
a) LowerCase b) CamelCase(‫)أول حرف فقط حرف كبير وبقية الحروف صغيرة‬
c) UpperCase d) None of them
6) What will be the output of the following C code?
#include <stdio.h>
void main()
{ printf("Hello World! %d \n", x);
}
a) Hello World! b) Hello World! x;
c) Compile time error d) Hello World! followed by a junk value
7) The format identifier ‘%i’ is also used for _____ data type.
a) char b) int c) float d) double
8) What is the priority of operators *, / and % in C language.?
a) * > / > % b) % > * > /
c) Both % = / , * are same d) All three operators *, / and % are same.
9) What is the output of the C Program.?
int a=0;
a = 10 + 2 * 12 /(3*2) + 5; (‫)نشتغل القوس اوﻻً ثم الضرب ثم القسمة ثم الجمع‬
printf("%d", a);
a) 19 b) 31 c) 66 d) 101
1
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
10) What will be the output of the following C code?
int a = 3;
int b = ++a + a++ + --a;
printf("Value of b is %d", b);
a)Value of x is 12 b) Value of x is 13
c)Value of x is 10 d) Undefined behavior
11) What is the output of the following code?
if (7<5)
if (3 < 7)
printf(“Math”);
else
printf(“Computer”);
else
printf(“Chemistry ”);
a) Math b) Computer c) Chemistry d) No output
12) What will be the output of the following C code?
int x = 1;
if (x > 0)
printf("inside if\n");
else if (x > 0)
printf("inside elseif\n");
a) inside if b) inside elseif c) inside if d) compile time error
inside elseif
13) What will be the output of the following C code?
int k = 0;
if (k = = 1)
if (k = = 0)
printf("Hello\n");
else
printf("Elex\n");
else
printf("Bye\n");
a) Hello b) Elex c) Bye d) compile time error
14) What is the output of C program with switch statement or block.?
char code='K';
switch(code)
{ case 'A': printf("ANT ");break;
case 'K': printf("KING "); break;
default: printf("NOKING");
}
printf("PALACE");
a) KING PALACE b) KING NOTHING PALACE
c) ANT KING PALACE d) Compiler error for using Non Integers as CASE constants.
15) What will be the output of the following C code?
2
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
int a = 1, b = 1;
switch (a)
{ case a*b:
printf("yes ");
case a-b:
printf("no\n");
break;
}
a) yes b) no c) yes no
d) Compile time error( ‫ﻻ يمكن متغيرات وﻻ معادﻻت‬, ‫ يجب ان تكون قيم ثابتة‬ase‫) ﻻن القيم مع ال‬

16) What will be the output of the following C code?


switch (ch)
{ case 'a':
case 'A':
printf("true");
}
a)if(ch = =‘a’ && ch = = ‘A’) b) if(ch = = 'a') if(ch = ='a') c) if(ch = =‘a’ || ch = = ‘A’)
printf(“true”); printf("true"); printf("true");
d) none of the mentioned
17) What is the output of C Program.?
int a=14;
while(a<20)
{ ++a;
if(a>=16 && a<=18)
{ continue;
}
printf("%d ", a);
}
a) 15 16 17 18 19 b) 15 18 19 c) 15 16 20 d) 15 19 20
18) What is the output of C Program.?
int a=10,b=20;
if(a==9 AND b==20) && ‫يتم استخدام الرمز‬
printf("Hurray..");
if(a==10 OR b==21) || ‫يتم استخدام الرمز‬
printf("Theatre");
a) Hurray Theatre b) Theatre c) No output d) Compiler error
19) What is the output of C Program.? int main() { int a[]; a[4] = {1,2,3,4}; printf("%d", a[0]); }
a) 0 b) 1 c) 2 d) Compiler error
20) How many times print Hello statement
for(i=1;i>=10;i+=2)
printf("Hello");

3
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
a) 0 b) 1 c) 5 d) 10
21) What is the output of C Program.? int a[3] = {10,12,14}; a[1]=20; int i=0; while(i<3) {
printf("%d ", a[i]); i++; }
a) 20 12 14 b) 10 20 14 c) 10 12 2 d) Compiler error
22) What is the output of C program with arrays.? int a[3] = {20,30,40}; int b[3]; b=a;
printf("%d", b[0]);
a) 20 b) 30 c) address of 0th element d) Compiler error
23) Find a C Storage Class below.
a) static b) auto c) register & extern d) All the above
24) Which among the following is a Global Variable.?
a) static b) auto c) register d) extern
25) To copy array element x to array of the same type y we use an expression y=x;
a) True b) False
26) A function which calls itself is called a ___ function.
a) Self b) Auto c) Recursive d) Static
27) How many values can a C Function return at a time.?
a) Only One Value b) Maximum of two values
c) Maximum of three values d) Maximum of 8 values
28) What is the output of C Program with functions.?
int sum(int,int);
int main()
{ int a=5, b=10, mysum;
mysum = sum(a,b);
printf("SUM=%d ", mysum);
printf("SUM=%d", sum(10,20));
return 0;
}
int sum(int i, int j)
{
return (i+j);
}
a) SUM=15 SUM=30 b) SUM=30 SUM=15
c) SUM=15 SUM=15 d) SUM=30 SUM=30
29) Arguments passed to a function in C language are called ___ arguments.
a) Formal arguments b) Actual Arguments
c) Definite Arguments d) Ideal Arguments
30) Choose a correct statement about C language function arguments.
a) Number of arguments should be same when sending and receiving
b) Type of each argument should match exactly
c) Order of each argument should be same d) All the above

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

Question No(3):
1) Rewrite the following program using switch statement?
switch(color)
{ case ‘b’: printf(“Blue”);
break;
case ‘r’:printf(“Red”); if (color =='b')
break; printf(“Blue”);
case ‘g’:printf(“Green”); else
break; if (color =='r')
default: printf(“Red”);
printf(“White”); else
} if (color =='g')
printf(“Red”);
else
printf(“White”);

int k, j;
2) Convert the following to k=1;
do-while loop? j=10;
int k, j; do
for(k=1, j=10; k <= 5; k++)
{ printf("%d ", (k+j));
{
k++;
printf("%d ", (k+j));
} }while(k <= 5);

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) Define
a) User defined function
Function that Defined by the programmer
b) Actual(‫ )الفعلي‬Variable
Variables used in function calling

c) Pass(call) by Value

Pass(call) by Value Copy of argument passed to function


Changes in function do not effect original
5
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
Use when function does not need to modify argument(Avoids accidental changes)
Question No(4):
1) Write a program that print the following shape :
1
22
333
4444
55555
int i,j,k;
for(i=1;i<5;i++)
{
for(j=4;j>i;j- -)
printf(" ");
for(k=1;k<=i;k++)
printf("%d",k);
printf("\n");
}

2) Create an array with 10 numbers and receive data in array and then print elements in
reserve order

int i,a[10];
printf("Enter array elements \n");
for(i=0;i<=9;i++)
scanf("%d",&a[i]);
printf("Array elements in reserve order ");
for(i=9;i>=0;i--)
printf("%d",a[i]);

3) Write a full program that receive from the user the length and width of a rectangular in
a main function,then calls a function with that vlaues to calculate the area of a
rectangular and returned them to calling function
‫ والتي تقوم بحساب مساحة‬recArea‫)برنامج يستقبل من المستخدم طول وعرض المستطيل ويقوم باستدعاء الدالة‬
.( main‫ ثم طباعة مساحة المستطيل داخل ال‬main ‫المستطيل وارجاعها الي الدالة الرئيسية‬
float recArea(float w,float l)
{ float result;
result=w*l;
return result;
}
void main( )
{ float length,width,area;
printf("Enter length of rectangular:");
scanf("%f",&length);
6
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
printf("Enter width of rectangular:");
scanf("%f",&width);
area= recArea(length,width);
printf("The area of rectangular:%f",area);
}

Question No(5):
1) What is the output of the following programs
1) int x=1; 5)
if (x > 3) void m();
{ if (x > 4) void n();
printf("Elex"); void z(int x);
else int x = 5;
printf("Civil"); void main()
} { int x = 3;
else { int x=24;
if (x < 2) printf("%d \n", x);
if (x != 0) }
printf("Engineering"); printf("%d \n", x);
printf("SUST"); m();
n();
Engineering SUST z(x);
printf("%d \n", x);
2) }
int k = 8; void m()
int m = 7; { int x = 8;
int x; printf("%d \n", x);
x=(k<m)? k++ : m--; }
printf("%d \n", k); void n()
printf("%d \n",--m); {
printf("%d \n", x);
printf("%d \n", x);
8
}
5
void z(int x)
7

7
‫من يتق ﷲ يجعل له مخرجا ً ومن يتوكل على ﷲ فهو حسبه‬
3) { x=10;
int i = 0, j = 0; printf("%d \n", x);
for (i; i < 2; i++){ }
for (j = 0; j < 3; j++)
{ printf("1\n"); 24
break; 3
} 8
printf("2\n"); 5
} 10
printf("after loop\n"); 3
1
2
1
2
after loop
4)
void fun();
int main() {
fun();
fun();
return 0; }
void fun() { static int a = 10;
printf("a = %d\n", a);
a++; }

a = 10
a = 11

With My best Wishes


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

You might also like