You are on page 1of 3

Al-Quds University

Computer Engineering Department


1st Hour Exam 2014

Student Name:______________________ SID:___________________ time:40 minutes

QUESTION 1

A C program contains the following declarations and initial assignments:

int i=15, j=8, k=2;


float x= 0.5 , y= -1.0, z;
char c=’s’, s=’x’;
/* character ‘s’ is 115, and ‘x’ is 120 */

Use the variables initially assigned to the variables for each expression to determine the
value of each the following expressions:

(8*i-2*j+21)%(2*s-c) 0

+j - ++y/-k; 23????

c = = s; 0

('x'-'s')/(j=x=5) 0

i*j> ‘x’ && ‘s’= =115 0

What will be output of the following printf statements for i = 91, x = 987.4321, id=204001

1. printf("|%-4d|%3.3d|%2d |",x, x, x);


987*|987*|987**
2. printf("|%.0f|%-8.3f|%6.1f |",y, y, y);
Compiler error, no ‘y’
variable

3. printf(" \"student:Nadi Lutfi\" \n \" \t :ID%d\" \n ",id);


"student:Nadi Lutfi"
" :ID204001"

QUESTION 2
What will the value of i and j be after it is executed
j=5;
for (i=0; i<5;i++)
{
j++;
++i;
}
a) i= 11 j=5 b) i=6 j=5 c) i=5 j=8 d) i=5 j=6 e) i=6 j=8

What is the value of i and j after the code bellow is executed?


int j=3, i=1;

if(j= =1)
j++; i++; ++j;
printf("%d %d", j,i);

a) 3 2 b) 5 2 c) 4 2 d) 3 1 e) 4 1

QUESTION 3

Answer if the following statements are True (T) or False (F)

1. #define CM PER INCH 2.54 T

2. #define PI 3.14
T
#include <stdio.h>

3. for( ; ; ); T

4. switch (num)
{
case 1;
printf (“num is 1”);
case 2; F
printf (“num is 2”);
?? default;
printf (“num is neither 1 nor 2”); }
QUESTION 4

Show the output generated by each of the following C programs?

a) b)
#include<stdio.h> #include<stdio.h>
main() main()
{ {
int i,j; int i,j;
i=1; i=1;
j=2;
do {
while(j<10) j = 1;
{ while(j <= 10)
if(i%3==0) {
j*=2; printf(" %3d",i*j);
++j; j++;
} }
++j; printf("\n");
printf("\n j=%d",--j); i++;
} }
while(i >= 10);
}

j=10 1 2 3 4 5 6 7 8 9 10

d)
#include<stdio.h>
main()
c) {
int i,j,k,x=0;
#include<stdio.h>
main() for (i=0, j = 6; j != i; i++, j--) {
{ switch(i) {
int j,i=2,k=99; case 1: ++i;
printf("\n x1=%d",i);
for(j=1;j<3;++j); break;
{ case 2: i++;
i++;k++;++i,j++; printf("\n x2=%d",i);
printf("\n k=%d",k); break;
printf("\n i=%d",i); case 3: --i;
} printf("\n x3=%d",i);
} break;
case 4: i--;
k=100 printf("\n x4=%d",i);
i=4 break;
default: x=i+j+k;
printf("\n other ");
}
printf("\n i=%d",i);
} other
} i=0
x1=2
i=2
x3=2
i=2

You might also like