0% found this document useful (0 votes)
186 views8 pages

The Test On C: 4mark

The document contains 12 multiple choice questions about C programming concepts like pointers, structures, file handling, recursion, and loops. The questions test understanding of how the given code snippets would compile and execute, including identifying errors, explaining outputs, and suggesting modifications.

Uploaded by

amitvit3
Copyright
© Attribution Non-Commercial (BY-NC)
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)
186 views8 pages

The Test On C: 4mark

The document contains 12 multiple choice questions about C programming concepts like pointers, structures, file handling, recursion, and loops. The questions test understanding of how the given code snippets would compile and execute, including identifying errors, explaining outputs, and suggesting modifications.

Uploaded by

amitvit3
Copyright
© Attribution Non-Commercial (BY-NC)
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

THE TEST ON C

TimeLeft=[Link]
1
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
2
#include <stdio.h>
typedef struct
{
char *name;
} Addr;

int main()
{
Addr *s;
char comm[10];
char *str = "Hello ";
Page 1 of 8
2/6/2009 [Link]
s = (Addr *)malloc(sizeof(Addr));
printf("Enter a name");
fgets(comm, 10,stdin);
s->name = (char *)malloc(sizeof(char[strlen(comm)]));
strcpy(s->name, comm);
strcat(str,s->name);
printf("%s", str);
}
What is this program trying to do? What are the bugs
in this? ?

4Mark
3
#define MAX 80
void f(char *to, char *from)
{
while(*from)
*to++ = *from++;

*to = '\0';
}

int main(void)
{
char str[MAX];

f(str, "this is a test");
printf(str);
}
What is this program trying to do? Explain. ?
Page 2 of 8
2/6/2009 [Link]

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

4Mark
5
struct sample
{
int a:6;
int b:12;
char s;
}st;


struct name
{
int a:28;
int b:12;
char ch;
}st1;
What would be the size of these two structures? Justify
your answer.
Note: int takes 4 bytes, char takes 1 byte. ?

4Mark
#define TOTAL_ELEMENTS sizeof(array) / sizeof
Page 3 of 8
2/6/2009 [Link]
6
(array[0])

int array[] = {23,34,12,17,204,99,16};

int main()
{
int d;
for(d = 0; d <= TOTAL_ELEMENTS; d++)
printf("%d\n",array[d]);
return 0;
}
What would be the output of this program? Suggest at
least one modification in this code. ?

4Mark
7
void quiz(int i)
{
if(i>1)
{
quiz(i/2);
quiz(i/2);
}
printf("%d\n", i);
}

int main()
{
quiz(5);
}
Explain the output of this program? Also mention about
the order of function calls and returns. ?
Page 4 of 8
2/6/2009 [Link]

4Mark
8
#include <stdio.h>
int main()
{
FILE *fp;
char name[10];
fp = fopen("test","a");
fprintf(fp,"\n%s","1 a 1");
fp = fopen("test","r");
fscanf(fp,"%s",name);
printf("%s\n",name);
}
What is this program trying to do? Explain. What are
the pitfalls in the above program? ?

4Mark
9
void f(void)
{
static int s = 0;
s++;
if(s == 10)
return;
f();
printf("%d ", s);
}

int main(void)
Page 5 of 8
2/6/2009 [Link]
{
f();
}
Explain the output of this program. ?

4Mark
10
int main()
{
int c = 0;
do
{
int c = 0;
++c ;
printf("\n c = %d ", c );
}
while( ++c <= 3 );

printf("\n c = %d\n", c );
}
What will be the ouptut of this program? Justify your
answer. ?

4Mark
int main()
{
int a = 10,*j;
void *k;
j = &a;
Page 6 of 8
2/6/2009 [Link]
11
k = &a;
*j++;
printf("%d",*j);
printf("%d" ,*k);
}
Identify the compilation error in this code. If the line
having the error is commented, what would be the
output? Justify your answer. ?

4Mark
12
enum {FALSE,TRUE};

int main()
{
int i=1;
do
{
printf("%d\n",i);
i++;
if(i < 5)
continue;
else
i = 4;
}while(TRUE);
return 0;
}
Explain the output of this program. ?

4Mark
Page 7 of 8
2/6/2009 [Link]




submit
Page 8 of 8
2/6/2009 [Link]

You might also like