FinalElex Tec Ans
FinalElex Tec Ans
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
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