Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

THE TEST ON C

TimeLeft=1:34:43
1
int main(void)
{
char ch;
int i;
ch = 'd';
ch = ~ch;

for( i = 128; i > 0; i = i / 2 )
if(i & ch)
printf("1 ");
else
printf("0 ");
}
What does this program do? Explain. ?

4Mark
2
int main()
{
long num1 = 0;
long num2 = 0;
long *pnum = NULL;

pnum = &num1;
*pnum = 2;
++num2;
num2 += *pnum;
Page 1 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=488&s2=20302

pnum = &num2;
++*pnum;
}
What will be the final value of num1 and num2?
Explain. ?

4Mark
3
#define SIZE 3
void fun(int *ptr)
{
*ptr = *ptr + 1;
}

int main()
{
int oldval;
const int newval = 0;
static int temp = 99;
int i;
for (i=0;i< SIZE;i++)
{
oldval = newval;
newval = i;
fun(&temp);
}
printf("%d %d %d",oldval,newval,temp);
}
There is an error in this program. Identify that. If the
line containing error is commented, what would be the
output? ?
Page 2 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=488&s2=20302

4Mark
4
#define MAX 10
int main()
{
int low[MAX];
int index;
int *high[3];
for(index = 0; index < MAX; index++)
high[index] = low + index;
}
What is this program trying to do? What could be a bug
here? ?

4Mark
5
Compare and constrast following two functions. Also
point out the bugs, if any.

#define MAX 50
int fun1()
{
char *s;
s=(char *) malloc (MAX*sizeof(char));
s="hello";
free(s);
}

int fun2()
Page 3 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=488&s2=20302
{
char *s;
s=(char *) malloc (MAX*sizeof(char));
strcpy(s,"hello");
free(s);
} ?

4Mark
6
Explain the output of following progam.
int main()
{
char arr[] = "Its very beautiful";
char *ptr = "Hello world";
char *str = "Sieze the day";

ptr = &arr[0];
printf("%s\n", ptr);

ptr = &str[0];
printf("%s\n", ptr);
} ?

4Mark
If the content of a file (input) is

abc
def

Page 4 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=488&s2=20302
7
and the following program is executed to take input
from the file:

char input[100],ch;
void main( void )
{
FILE *fp;
fp = fopen("input","rb");
fscanf(fp, "%s" ,&input);
fscanf(fp, "%c" ,&ch);
}

What will be the value of input and ch? Reason your
answer. ?

4Mark
8
void fun1(void)
{
static int dummy = 5;
dummy = dummy + 10;
printf("%d",dummy);
}
void fun2(char *c)
{
*c = *c + 2;
printf("%d",dummy);
printf("%c", *c);
}
int main()
{
char ch = 'A';
Page 5 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=488&s2=20302
fun1();
fun2(&ch);
printf("%c", ch);
}
The above program gives a compilation error. What is
that?
If the line that gives the error is commented, what
would the output? ?

4Mark
9
Place holder for Large Question (To de done on
server) ?

4Mark
10
Explain the output of the following program? Is it
better to use a fuction rather than macro here?

#define swap(a,b,c) c = a; a = b; b = c;
int main()
{
int a = 3,b = 5;
int temp;
swap(a,b,temp);
printf("%d %d %d\n",a,b,temp);
} ?
4Mark
Page 6 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=488&s2=20302

11
Explain the output of the following program.
int DoSomething (int a, int b)
{
if ( b == 0 )
return (a);
else
return (DoSomething(a-1, b-1));
}

int main()
{
printf("%d\n",DoSomething(20,23));
} ?

4Mark
12
typedef struct emp
{
int emp_code;
char* emp_name;
char grade;
double salary;
char gender;
struct emp* link;
}employee;
How do you modify the above structure to have less size
in view of byte padding? Justify your answer. (You may
Page 7 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=488&s2=20302




assume 32 or 64 bit architecture). ?

4Mark
submit
Page 8 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=488&s2=20302

You might also like