Knowledge check.
- Choose one best answer from given 4 choices for each questions.
- Review before submit as you wont get a chance to review after submit.
- Max Time for quiz is 30 mins and Exam is 90 mins.
- Login is not required for an exam or a quiz.
- By submitting you formally acknowledge and accept terms and conditions mentioned here.
Give the output of the following code snippet :
int main()
{
union a
{
int val;
char ch[2];
};
union a unobj;
unobj.ch[0]=10;
printf("%d %d", unobj.ch[0]);
return 0;
}
Give the output of the following code snippet :
int main()
{
int *p = (int *)2;
int *q = (int *)3;
printf("%d", p - q);
}
Give the output of the following code snippet :
void func(float *i)
{
*i=200.5;
}
void func2(float i)
{
i=300.75;
}
int main()
{
float i=100.25;
func(&i);
func2(i);
printf("%.2f ", i);
}
Give the output of the following code snippet :
int main()
{
char str[] = "Hello";
char *s = str;
printf("%s\n", s++ +3);
return 0;
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
struct node *prev;
}*head;
void func( int num )
{
struct node *temp,*temp2;
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
temp->prev=NULL;
head=temp;
}
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
temp2->prev=temp;
}
}
void displayrev()
{
struct node *r;
r=head;
while(r->next!=NULL)
r=r->next;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->prev;
}
printf("\n");
}
void display()
{
struct node *r;
r=head;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
printf("\n");
}
void main()
{
func(100);
func(200);
func(300);
func(400);
display();
displayrev();
}
Give the output of the following code snippet :
void func(int arr[][5])
{
**arr++;
printf("%d ",**arr+1);
}
int main()
{
int arry[][5]= {1,2,3,4,5,6};
func(arry);
printf("%d ",**arry+2);
}
Give the output of the following code snippet :
union p
{
int x;
char y;
};
int main()
{
union p p1[] = {1, 92, 3, 96};
union p *ptr1 = p1;
printf("%d\n",p1[1].y);
}
Give the output of the following code snippet :
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
} p;
int x;
};
int main()
{
union u u1 = {2};
printf("%d\n", u1.p.x);
}
Give the output of the following code snippet :
void main()
{
int x, *ptr1;
_asm
{
mov dword ptr[x], 14h
lea eax, [x]
mov dword ptr[ptr1], eax
mov ecx, dword ptr[x]
sub ecx, 0Ah
add ecx, dword ptr[x]
mov dword ptr[x], ecx
}
printf("%d ", *ptr1);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax,a
mov ebx,b
mov c,eax
mov a,ebx
mov b,eax
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
void main()
{
char *str;
char *str2;
str="Hello";
str2="World";
strcpy(str,str2);
printf("%s",str);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 400;
void func();
/* Test1.c */
#include "Test1.h"
static int value = 100;
void func()
{
static int value = 200;
printf ( "Output = %d\n", value );
value = 300;
}
/* Test2.c */
static int value = 100;
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
int BinaryToOctal(long int binarynum)
{
long int octalnum = 0, j = 1, remainder;
while (binarynum != 0)
{
remainder = binarynum % 10;
octalnum = octalnum + remainder * j;
j = j * 2;
binarynum = binarynum / 10;
}
printf("%lo", octalnum);
return 0;
}
void main()
{
BinaryToOctal(1000);
}
Consider the given code given below : What do the nodes temp1 and temp3 point to?
temp3=temp1=Head;
temp2=temp1->next;
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
Give the output of the following code snippet :
typedef int val1;
#define INT float;
void main()
{
val1 a=100,b=200;
INT x=10,y=20;
printf("%d %d",a+b,x+y);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
}*head=0;
int count()
{
struct node *n;
int c=0;
n=head;
while(n!=NULL)
{
n=n->next;
c++;
}
printf("%d",c);
return 0;
}
void add( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
head=temp;
}
int Delete(int num)
{
struct node *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=temp->next;
free(temp);
return 1;
}
else
{
prev->next=temp->next;
free(temp);
return 1;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return 0;
}
void main()
{
struct node *n;
add(100);
add(200);
add(300);
Delete(100);
Delete(200);
count();
}
Give the importance of the following lines of code in the below function :
struct node
{
int data;
struct node *next;
}*head;
void func(int val)
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
}
Give the output of the following code snippet :
void main()
{
int a=10,b=20,c=30;
unsigned int d=12;
int x=10,y=20,z=30;
x=a | b | c;
y|=3;
z=d & d;
printf("%d %d %d",x,y,z);
}
Give the output of the following code snippet :
void BinaryToDecimal(int num)
{
int binary_val, decimal_val = 0, base = 1, rem;
while (num > 0)
{
rem = num % 10;
decimal_val = decimal_val + rem * base;
num = num / 10 ;
base = base * 2;
}
printf("%d ", decimal_val);
}
void main()
{
BinaryToDecimal(10001000);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c 100 200 300
int main(int argc, char *argv[])
{
int i=0;
int sum=0;
while(i!=argc)
{
printf("%s ",*argv);
i++;
}
}
Give the output of the following code snippet :
void main()
{
int arry[10]= {1,2,3,4};
printf("%d",*(arry+6));
}
Predict the output of the following code snippet :
int Delete(int num)
{
struct node *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=temp->next;
free(temp);
return 1;
}
else
{
prev->next=temp->next;
free(temp);
return 1;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return 0;
}
void main()
{
add(100);
add(200);
Delete(100);
Delete(200);
Delete(300);
display();
}
Give the output of the following code snippet :
void func(int *val)
{
*val+=10;
}
void main()
{
const int arry[10]= {1,2,3,4,5};
func(&arry[0]);
char str[15]="Hello World";
arry[2]=10;
str[0]='Y';
printf("%d %s",arry[2]+arry[0],str);
}
Give the output of the following code snippet :
void main()
{
typedef char ptr,*qtr;
char fptr=100;
qtr a,b;
ptr p=20,q=p++;
a=&fptr;
b=&q;
printf("%d %d",*a,*b);
}
Give the output of the following code snippet :
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
struct student *m = &s;
printf("%d", sizeof(m));
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20,c=5;
_asm
{
mov ecx,0
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
add ecx,10
and ecx,ebx
or ecx,eax
mov dword ptr[c],ecx
}
printf("%d",c);
}
Give the output of the following code snippet :
void main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
__asm
{
push 100
push 200
mov eax,Func
call eax
mov ebx,End
jmp ebx
Func :
add esp,4
pop eax
mov a, eax
pop eax
mov b, eax
sub esp,0x8
ret
End : add esp, 0x8
}
printf("%d %d", a, b);
}
Give the output of the following code snippet :
nt _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b = 0;
__asm
{
call Label2
mov a, 100
call Label3
mov eax, a
cmp eax,200
jne End
Label2 : mov b, 200
ret
Label3: mov a,200
ret
End : mov b,300
}
printf("%d %d", a, b);
}
Give the output of the following code snippet run with the following commandline arguments:
>Testfile.c Yellow Jello
/* Testfile.c */
int main(int argc, char *argv[])
{
printf("%c", *++argv[1] );
return 0;
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b = 0;
__asm
{
call Label2
mov a, 100
jmp Label3
Label2 : mov b, 200
ret
Label3: mov a,200
}
printf("%d %d", a, b);
}
After the execution of the particular loop given below, where is the final result stored in ?
while(temp1!=NULL)
{
temp3=temp2;
temp2=temp1;
temp1=temp1->next;
temp2->next=temp3;
}
void ReverseList()
{
node *temp1,*temp2,*temp3;
temp1=Head;
temp2=NULL;
while(temp1!=NULL)
{
temp3=temp2;
temp2=temp1;
temp1=temp1->next;
temp2->next=temp3;
}
Head=temp2;
}
Give the output of the following code snippet :
void print(int num,int num2,...)
{
int i;
va_list marker;
va_start(marker,num);
while((--num) != 0)
{
i=va_arg(marker,int);
printf("%d ",i);
}
va_end(marker);
}
int main(int argc, char *argv[])
{
print(4,3,20,30);
}
Give the output of the following code snippet :
int main()
{
char ch = 'c';
char *chptr = &ch;
printf("%c",*chptr);
}
Give the output of the following code snippet :
int main()
{
char str1[15] = "Hello World";
char ch = 'W';
char *str;
str=strchr(str1,ch);
printf("%s ", str);
return 0;
}
Give the output of the following code snippet :
struct stud
{
int age;
char *name;
} stud;
void main()
{
printf("%d",sizeof(stud));
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
struct node *prev;
}*head;
void func( int num )
{
struct node *temp,*temp2;
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
temp->prev=NULL;
head=temp;
}
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
temp2->prev=temp;
}
}
void display()
{
struct node *r;
r=head;
while(r->next!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
}
void main()
{
func(100);
func(200);
func(300);
func(400);
display();
}
Give the output of the following code snippet : Assume the input given is 100.25
void main()
{
int i=3;
int x;
do
{
scanf("%d",&x);
ungetc(x,stdout);
printf("%d ",x);
ungetc(x,stdin);
i--;
}
while(i>3);
}
Give the output of the following :
int main()
{
int a = 100;
void *p = &a;
int *ptr =(int *) p;
printf("%d",*ptr);
return 0;
}
Give the output of the following code snippet :
int main()
{
int i=100,*p,*p1;
p=&i;
p1=p;
printf("%d",*p1);
}
Give the output of the following code snippet :
void f(int *p, int *q)
{
p = q;
*p = 2;
}
int i = 0, j = 1;
int main()
{
f(&i, &j);
printf("%d %d \n", i, j);
}
Give the output of the following code snippet :
void main()
{
int a[2][2] = {1, 2, 3, };
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
printf("%d ", *a[i][j]);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
struct node *prev;
}*head;
void func( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
temp->prev=NULL;
while(head!=NULL)
head=head->next;
head=temp;
}
void display()
{
struct node *r;
r=head;
while(r->next!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
}
void main()
{
func(100);
func(200);
func(300);
func(400);
display();
}
Give the output of the following code snippet :
void main()
{
char s1[]="Hello";
char *s2;
int len=sizeof(s1);
s2=(char*)malloc(len);
memcpy(s2,s1,len);
puts(s2);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value;
void func();
/* Test1.c */
extern int value;
void func()
{
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void main ()
{
printf ( "Output = %d\n", value );
func();
}
Give the output of the following code snippet :
int main()
{
float x = 0.3;
int y=10;
if (x > 0.3f)
printf("%d",(int)(2*3+6/3.0));
else
printf("%d",(int)(2*3+6*3.0));
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 300;
/* Test1.c */
extern int value;
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void func();
void main ()
{
printf ( "Output = %d\n", value );
func();
}
Give the output of the following code snippet :
void func(char *s)
{
int len=0;
while(*s!='\0')
{
len++;
}
printf("%d",len);
}
void main()
{
char str1[15]="Hello World";
char *x;
x=str1;
func(x);
}
Give the output of the following code snippet :
struct node
{
int x;
struct node *next;
}*Head;
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
void AddNode( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->x=num;
temp->next=Head;
Head=temp;
}
void Display()
{
struct node *r;
r=Head;
while(r->next!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(20);
AddNode(3);
Display();
SortList();
Display();
}
Give the output of the following code snippet :
struct
{
char *name;
union
{
char *sval;
} u[5];
} symtab[10];
void main()
{
symtab[0].u[0].sval="HelloWorld";
printf("%s",symtab[0].u[1].sval);
}
Give the output of the following code snippet :
int main()
{
int i = 5, a = 10;
_asm
{
Label2: cmp dword ptr[i], 0
je Label1
mov eax, dword ptr[i]
sub eax, 1
mov dword ptr[i], eax
mov ecx, dword ptr[a]
add ecx, dword ptr[i]
mov dword ptr[a], ecx
jmp Label2
}
Label1:printf("%d", a);
}
Give the output of the following code snippet :
void func(int *arr)
{
int *p;
p=arr;
*arr++;
printf("%d %d",sizeof(*arr),*p);
}
int main()
{
int arry[10]= {1,2,3,4,5,6};
func(arry);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c Hello World Program
int main(int argc, char *argv[])
{
int i=strlen(argv[3]);
int sum=0;
while(argc)
printf("%s ",argv[argc]);
}
Give the output of the following code snippet :
int main()
{
int x=10,y=10,z=20;
int a= x!=10 && z==30;
int b= x&y;
int c= x-- > y++;
printf("%d %d %d",a,b,c);
}
Give the output of the following code snippet :
int DecimalToOctal(long quotient)
{
long remainder;
int octalNumber[100], i = 1, j;
while (quotient != 0)
{
octalNumber[i++] = quotient % 8;
quotient = quotient / 8;
}
for (j = i - 1; j > 0; j--)
printf("%d", octalNumber[j]);
return 0;
}
void main()
{
DecimalToOctal(100);
}
Consider the given code given below : Give the importance of the nodes temp4 and temp5.
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
What do the following lines of code in the function indicate?
while(temp!=NULL)
void Delete(int num)
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=head->next;
head->prev=NULL;
}
else
{
if(temp->next==NULL)
temp->prev->next=NULL;
else
{
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
}
}
free(temp);
return;
}
temp= temp->next;
}
}
Give the output of the following code snippet : Assume the contents of the file 'Test.txt' is "Hello World".
void main()
{
FILE *fp,*fp1;
char x[20];
fp = fopen("Test.txt","r");
int i=0;
while(fgets(x,12,fp)!=NULL)
{
printf("%s",x);
}
fclose(fp);
}
Give the output of the following code snippet :
void main()
{
int a=10,c=20,b=10;
_asm
{
mov eax,20
mov ebx,a
sub eax,dword ptr[b]
jbe Label2
and eax,c
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,eax
je Label1
or eax,50
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int main()
{
int i, j, k, prod = 0;
_asm
{
mov dword ptr[i], 1
mov dword ptr[j], 2
mov dword ptr[k], 1
jmp Label1
Label3 : mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
mov ecx, dword ptr[j]
add ecx, 1
mov dword ptr[j], ecx
mov edx, dword ptr[k]
add edx, 1
mov dword ptr[k], edx
Label1 : cmp dword ptr[i], 3
jg Label2
mov eax, dword ptr[i]
imul eax, dword ptr[j]
imul eax, dword ptr[k]
mov dword ptr[prod], eax
jmp Label2
jmp Label3
}
Label2: printf("%d ", prod);
}
Give the output of the following code snippet :
int main()
{
int x=10,y=1;
int z=++x || y--;
if(z < x^y || y%x)
printf("%d",z++- ++x);
else
printf("%d",z--+ --y);
}
Give the output of the following code snippet :
int sum(int first,...)
{
int sum=0, count=0,i=first;
va_list marker;
va_start(marker,first);
while(i!=-1)
{
sum+=i;
count++;
i=va_arg(marker,int);
}
va_end(marker);
return sum;
}
int main(int argc, char *argv[])
{
printf("%d",sum(2,3,4,5,6,-1));
}
Give the output of the following code snippet :
int main()
{
int (*p)[5];
int a[][5]= {1,2,3,4,5,6};
p=a;
p++;
int *q[]= {*a,*a+1,*a+2,*a+3,*a+4};
printf("%d %d %d",**q+4,**p+3,*(*(a+3)+2));
}
Give the output of the following code snippet :
void main()
{
char str[12]="Hello world";
char *str1="Yellow World";
str[5]='L';
printf("%s",str);
}
Give the output of the following code snippet :
struct
{
char *name;
union
{
char *sval;
} u;
} symtab[10];
void main()
{
symtab.u.sval="HelloWorld";
printf("%s",symtab.u.sval);
}
Give the output of the following code snippet :
void main()
{
int i = 12, a = 10;
_asm
{
mov eax, dword ptr[i]
and eax, 80000001h
jns Label1
dec eax
or eax, 0FFFFFFFEh
inc eax
Label1 : test eax, eax
jne Label2
mov dword ptr[a], 12Ch
}
Label2: printf("%d", a);
}
Give the output of the following code snippet :
int main()
{
int i=5, *j, k;
j = &i;
*j+=1;
printf("%d\n", i**j-*j);
return 0;
}
Give the output of the following code snippet :
int main()
{
struct Temp
{
int one:2;
};
struct Temp var = {1};
printf("%d\n", var.one);
return 0;
}
Give the output of the following code snippet :
char *func()
{
char *str;
str="Hello World";
return str;
}
void main()
{
char s[20];
s=func();
printf("%s",s);
}
Give the output of the following code snippet :
void main()
{
typedef unsigned int uint;
uint x=-100,y=200;
unsigned int a=300,b=400;
int z;
printf("%d",x-y/a+b);
}
Give the output of the following code snippet : Assume the contents of the file 'Test.txt' is
Hello World
void main()
{
char ch;
char str[10];
int count=0;
FILE *fp;
int i=0;
fp=fopen("Test.txt","r");
while((ch=getc(fp))!=EOF)
{
if(ch=='\n'|| ch==' ')
{
i++;
}
}
printf("%d",i);
fclose(fp);
}
Give the output of the following code snippet :
int main()
{
int ary[4] = {1, 2, 3, 4};
printf("%d\n", *(ary+2));
}
Give the output of the following code snippet :
int main()
{
char *MemAlloc;
MemAlloc = (char*)malloc(20 * sizeof(char) );
strcpy( MemAlloc,"SourceLens");
printf("%s",MemAlloc);
}
Give the output of the following code snippet :
void print(int num,va_list marker);
void disp(int num,...)
{
va_list val;
va_start(val,num);
print(num,val);
}
void print(int num,va_list marker)
{
int i,k,j;
for(i=0; i< num; i++)
{
j=va_arg(marker,int);
printf("%d ",j);
}
va_end(marker);
}
int main(int argc, char *argv[])
{
disp(4,10,20,30);
}
Give the output of the following code snippet :
void main()
{
int a=30,c=10,b=40;
_asm
{
mov eax,30
mov ebx,dword ptr[c]
sub eax,ebx
jnge Label2
shl eax,1
xor eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
jz Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value=100;
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
int value = 100;
void main ()
{
printf ( "Output = %d", value );
}
Give the output of the following code snippet :
void main()
{
char str[]="Hello world";
char *str1="Hello world";
if(strcmp(str,str1)==0)
printf("True");
else
printf("False");
}
Give the output of the following code snippet :
typedef struct
{
int a;
} Temp;
void main()
{
Temp t1;
t1.a=100;
printf("%d",t1.a);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
int main()
{
struct point p1[] = {1, 2, 3, 4, 5, 6};
struct point *ptr1 = p1;
printf("%d ",ptr1->x);
}
Give the output of the following code snippet :
union p
{
int x;
char y;
};
int main()
{
union p p1,p2;
p1.y = 60;
p2.x = 12;
printf("%d\n", p2.y);
}
Give the output of the following code snippet :
typedef void v;
v func(int,int);
void main()
{
func(10,10);
}
v func(int x,int y)
{
printf("%d",x+y);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
extern int value;
void func();
/* Test1.c */
int value;
void func()
{
printf ( "Output = %d", value );
}
/* Test2.c */
#include "Test1.h"
void main ()
{
extern int value;
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 5;
_asm
{
Label3: cmp dword ptr[i], 0
je Label1
mov eax, dword ptr[a]
add eax, dword ptr[j]
mov dword ptr[a], eax
mov ecx, dword ptr[j]
add ecx, 1
mov dword ptr[j], ecx
mov edx, dword ptr[i]
sub edx, 1
mov dword ptr[i], edx
cmp dword ptr[i], 2
jne Label2
jmp Label1
Label2 : jmp Label3
}
Label1:
printf("%d", a);
}
Give the output of the following code snippet :
int mod(int a, int b)
{
return a % b;
}
void main()
{
int (*fptr)()= &mod;
printf("%d",(*fptr)(10,6));
}
Give the output of the following code snippet :
void main()
{
int i = 0, a = 10;
_asm
{
Label2: cmp dword ptr[i], 2
jne Label1
mov eax, dword ptr[a]
add eax, 1
mov dword ptr[a], eax
Label1 : mov ecx, dword ptr[i]
add ecx, 1
mov dword ptr[i], ecx
cmp dword ptr[i], 5
jne Label2
}
printf("%d", a);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c Hello World
void func(char *arry[])
{
for(int i=1; i< =3; i++)
printf("%s ", (arry[i])+2);
}
int main(int argc, char *argv[])
{
func(argv);
return 0;
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value;
void func();
/* Test1.c */
extern int value;
void func()
{
printf ( "Output = %d", value );
}
/* Test2.c */
void main ()
{
printf ( "Output = %d\n", value );
func();
}
Give the output of the following code snippet :
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%d %d", **r, a[0]);
}
Give the output of the following code snippet :
union p
{
int x;
char y;
};
int main()
{
union p p1;
union p *ptr1 = &p1;
ptr1->x=100;
ptr1->y='C';
printf("%c\n",ptr1->x);
}
Give the output of the following code snippet who's solution configuration has been set to the DEBUG mode :
int main()
{
int a = 200, b = 100, c = 2;
_asm
{
mov eax, esp
mov ebx, 10
push eax
push ebx
mov ecx, esp
mov ebx, dword ptr[b]
sub ecx, eax
mov a, ecx
mov b, ebx
pop edx
add esp,8
}
printf("%d %d", a, b);
}
Give the output of the following code snippet :
void main()
{
char s1[]="Hello";
char *s2;
int len=sizeof(s1);
s2=(char*)malloc(len);
memcpy(s2,s1);
puts(s2);
}
Give the output of the following code snippet :
#define val 20
void main()
{
int arry[val]= {0};
char str[val]="Hello World";
arry[10]=10;
arry[5]=20;
str[3]='B';
printf("%d %s",arry[10]+arry[5],str);
}
Give the output of the following code snippet :
struct student
{
int mark1;
char *name1;
};
void main()
{
struct student stud;
stud.mark1=100;
stud.name1="Jenn";
struct student *s=&stud;
printf("%s",s->stud.name1);
}
Give the output of the following code snippet :
typedef struct stud *s;
void func(struct stud *stuobj);
struct stud
{
int no;
int no2;
s link;
};
void main()
{
struct stud s= {1001,1002};
func(&s);
}
void func(struct stud *stuobj)
{
struct stud *s;
s=stuobj;
printf("%d",s->no);
}
Give the output of the following code snippet :
void main()
{
int a=50,c=10,b=40;
_asm
{
mov eax,40
mov ebx,a
sub eax,dword ptr[b]
jae Label2
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
jne Label1
add eax,dword ptr[b]
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax,a
mov ebx,b
mov c,eax
mov dword ptr[a],eax
mov dword ptr[b],ebx
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
int main()
{
char *a[2] = {"Hello"};
printf("%d", sizeof(a));
return 0;
}
Give the output of the following code snippet :
void main()
{
int a = 10;
_asm
{
mov eax, dword ptr[a]
add eax, 5
mov dword ptr[ebp - 0D0h], eax
cmp dword ptr[ebp - 0D0h], 5
je Label1
cmp dword ptr[ebp - 0D0h], 0Ah
je Lable2
cmp dword ptr[ebp - 0D0h], 0Fh
je Lable3
jmp Lable4
Label1 : mov eax, dword ptr[a]
add eax, 0Ah
mov dword ptr[a], eax
Lable2 : mov eax, dword ptr[a]
add eax, 32h
mov dword ptr[a], eax
Lable3 : mov eax, dword ptr[a]
add eax, 64h
mov dword ptr[a], eax
}
Lable4: printf("%d", a);
}
Give the output of the following code snippet :
void f(int i)
{
printf("%d\n", i);
}
void (*func)(void) = f;
int main(int argc, char *argv[])
{
func(10);
return 0;
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 10, b = 10,c=10,d=10;
__asm
{
mov eax,Label1
call eax
mov ebx,Label2
mov ecx,10
mov edx,25
cmp edx,ecx
jz Label2
Label1 :
mov a, 20
mov d, 10
mov b,edx
ret
Label2 :
mov c,300
mov a,50
}
printf("%d %d %d %d", a,b,c,d);
}
Give the importance of the following lines of code :
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
Give the output of the following code snippet :
typedef struct p *q;
struct p
{
int x;
char y;
q ptr;
};
int main()
{
struct p p = {10, 20, &p};
printf("%d\n", p.ptr.x);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
void func();
/* Test1.c */
#include "Test1.h"
static int value;
void func()
{
printf ( "Output = %d\n", value );
}
/* Test2.c */
#include "Test1.h"
static int value;
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
int main()
{
int a = 15, b = 10, c;
_asm
{
mov eax,a
mov ebx,b
mov edx,dword ptr[c]
xor eax,ebx
or eax,edx
dec edx
mov dword ptr[a],eax
mov dword ptr[b],edx
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
void func(int *p,int count)
{
for(int i=0; i< count; i++)
printf("%d ", p[i]);
}
int main()
{
int arry[5]= {1,2,3,4,5};
func(arry,5);
}
Give the output of the following code snippet :
int main()
{
int arry[5]= {20};
arry[5]=10;
arry[6]=++(*arry);
printf("%d",0[arry]);
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 5, sum = 0;
_asm
{
Label2: cmp dword ptr[i], 0
je Label1
mov eax, dword ptr[sum]
add eax, dword ptr[a]
mov dword ptr[sum], eax
mov ecx, dword ptr[i]
sub ecx, 1
mov dword ptr[i], ecx
mov edx, dword ptr[j]
add edx, 1
mov dword ptr[j], edx
mov eax, dword ptr[a]
add eax, dword ptr[j]
mov dword ptr[a], eax
jmp Label2
}
Label1:
printf("%d %d", a, sum);
}
Give the output of the following code snippet :
void print(char *str,...)
{
int i;
va_list marker;
va_start(marker,str);
i=va_arg(marker,int);
i=va_arg(marker,int);
printf("%d",i);
va_end(marker);
}
int main()
{
print("Start ",2,4,-1);
}
Give the output of the following code snippet :
void main()
{
FILE *fp,*fp1;
char x;
fp = fopen("Test.txt","w+");
fputs("Hello World Program", fp);
fseek( fp, 6, SEEK_SET );
fputs("Yellow", fp);
fclose(fp);
fp1 = fopen("Test.txt","r");
while(1)
{
x = fgetc(fp);
if( feof(fp) )
{
break;
}
printf("%c", x);
}
fclose(fp1);
}
Files Test1.c, Test1.h, Test2.c and Test3.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
extern int value;
void func();
void func1();
/* Test1.c */
#include "Test1.h"
void func()
{
value=200;
printf ( "Output = %d\n", ++value );
}
/* Test2.c */
#include "Test1.h"
void func1()
{
value=200;
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
int value = 400;
void main ()
{
func1();
printf("Output = %d",value);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 300;
void func() {};
/* Test1.c */
extern int value;
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void func();
void main ()
{
printf ( "Output = %d\n", value );
func();
}
Give the output of the following code snippet :
int main()
{
enum Days {SUN,MON,TUES,WED,THURS,FRI,SAT};
Days day;
printf("%d",sizeof(day));
}
Give the output of the following code snippet :
int DecToBin(int num)
{
if (num == 0)
{
return 0;
}
else
{
return (num % 2) + 10 * DecToBin(num / 2);
}
}
int main()
{
printf("%d",DecToBin(2));
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c=2;
_asm
{
mov eax,a
mov ebx,b
mov c,eax
shl eax,dword ptr[c]
shl ebx,2
xor eax,ebx
mov dword ptr[a],ebx
mov dword ptr[b],eax
}
printf("%d %d",a,b);
}
Files Test1.c, Test1.h, Test2.c, Test2.h and Test3.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
void func1();
/* Test2.h */
extern int value;
void func();
/* Test1.c */
#include"Test2.h"
void func()
{
printf("Output = %d\n",value);
}
/* Test2.c */
#include"Test2.h"
int value = 200;
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test2.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
typedef struct
{
int no;
int no2;
stud *link;
} stud;
void main()
{
stud s;
s.no=10;
printf("%d",s.no);
}
Give the output of the following code snippet :
typedef int(*fptr)(int a);
typedef struct
{
int a;
fptr fpt[10];
} fp;
int fun(int a)
{
int sum = 0;
_asm
{
mov dword ptr[a], 24h
mov eax, dword ptr[a]
add eax, 1
mov dword ptr[a], eax
mov ecx, dword ptr[sum]
sub ecx, dword ptr[a]
mov dword ptr[sum], ecx
}
printf("%d", sum);
return 0;
}
int _tmain()
{
fp myS;
myS.fpt[1] = fun;
_asm
{
push 5Ah
mov ecx, 4
shl ecx, 0
mov edx, dword ptr[ebp + ecx - 28h]
call edx
add esp, 4
}
}
Give the output of the following code snippet :
int main()
{
int arr[5]= {20,10,5,0};
int arry2[]= {*arr,*arr+2,*arr+3,*arr+5};
int *p;
p=arry2;
p++;
arr[1]=10;
arry2[2]=++(*arr);
printf("%d %d",++*p,(*arr)+(*arry2));
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=30;
_asm
{
mov eax,10
mov ebx,a
sub eax,ebx
jb Label1
mov b,200
mov c,100
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void func(float *i)
{
i=200.5;
}
int main()
{
float i=100.25;
func(&i);
printf("%.2f ", i);
}
Give the output of the following code snippet :
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
struct student *m = &s;
printf("%d", sizeof(student));
}
Give the output of the following code snippet :
void f(float i)
{
printf("%d\n", i);
}
void (*fptr)(float) = f;
void main()
{
fptr(100);
}
Give the output of the following code snippet :
struct st
{
int x;
struct st *next;
};
int main()
{
struct st temp;
temp.x = 10;
temp.next = temp;
printf("%d", temp.next.x);
return 0;
}
Give the output of the following code snippet :
void main()
{
double a=100.25;
double b=200.25;
double c = ((a) == (b) ? (++a) : (--b));
double d= ((a) >= (b) ? (a--) : (--b));
double e= (c > d) ? c : d;
printf("%.2f %.2f %.2f",c,d, e);
}
Give the output of the following code snippet who's solution configuration has been set to the DEBUG mode :
int main()
{
int a = 200, b = 100, c = 2;
_asm
{
mov eax, esp
mov ebx, 10
push dword ptr[b]
push eax
push ebx
mov ecx, esp
pop dword ptr[b]
mov ebx, dword ptr[b]
sub ecx, eax
mov a, ecx
mov b, ebx
}
printf("%d %d", a, b);
}
Give the output of the following code snippet :
int main()
{
int c=10;
_asm
{
mov eax,10
div dword ptr[c]
mov c, eax
}
printf("%d", c);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
}*head=0;
void display(struct node *r)
{
r=head;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
}
void add( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
head=temp;
}
int Delete(int num)
{
struct node *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=temp->next;
free(temp);
return 1;
}
else
{
prev->next=temp->next;
free(temp);
return 1;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return 0;
}
void main()
{
struct node *n;
add(100);
add(200);
display(n);
add(300);
Delete(100);
display(n);
Delete(200);
}
Give the output of the following code snippet :
void first()
{
printf("Hello World");
}
void main()
{
void (*ptr)();
ptr=&first;
ptr();
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b = 0;
__asm
{
call Label2
mov a, 100
call Label2
mov eax, a
cmp eax,200
jne End
Label2 : mov b, 200
ret
Label3: mov a,200
ret
End : mov b,300
}
printf("%d %d", a, b);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
void func(struct point);
int main()
{
struct point p1 = {1, 2};
func(p1);
printf("%d\n", p1.x);
}
void func(struct point p)
{
p.x = 10;
}
Consider the given lines of code : What does the line below signify?
if(head == NULL)
void add( int num )
{
struct node *temp;
if (head== NULL)
{
head=temp;
head->next=NULL;
}
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
head=temp;
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax,a
mov ebx,b
add eax,ebx
mul a
mov b,ebx
}
printf("%d",a);
}
Give the output of the following code snippet :
int main()
{
char *MemAlloc;
MemAlloc = (char*)calloc(20,sizeof(char) );
strcpy( MemAlloc,"SourceLens");
printf("%s",*MemAlloc);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
void fun(struct point p[])
{
printf("%d %d\n",p[1].y,++p[1].y);
}
int main()
{
struct point p1[] = {1, 2, 3, 4};
fun(p1);
}
Give the output of the following code snippet :
void main()
{
int x=10,y=20,arr[3],i;
for(i=0; i< 3; i++)
{
arr[i]=++x;
if(arr[i]!=x++ || arr[i]==++x)
printf("Hello ");
else
printf("World");
break;
}
}
Give the output of the following code snippet :
int main()
{
int arry[5]= {20,10,5,0};
arry[5]=10;
arry[6]=++(*arry);
printf("%d %d",3[arry],sizeof(arry));
}
Give the output of the following code snippet :
union Test
{
char str;
};
int main()
{
union Test st1, *st2;
st1.str='D';
st2 = &st1;
st1.str = 'J';
printf("%c",st2->str);
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=30;
_asm
{
mov eax,60
mov ebx,b
sub eax,ebx
jnb Label1
mov b,200
mov c,100
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int main()
{
int a = 20, b = 20,c=2;
_asm
{
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
shl eax,2
inc eax
add eax,ebx
mov dword ptr[a],eax
}
printf("%d",a);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c Hello World
int main(int argc, char *argv[])
{
int i=0;
while(i!=argc)
{
printf("%s ", argv[i]);
i++;
}
return 0;
}
Give the output of the following code snippet :
void main()
{
int a=0x10,b=20,c=30,d;
int x,y,z;
x=a & b &c;
y=a | b |c;
z=x && y | c;
printf("%d %d %d",x,y,~z);
}
Give the output of the following code snippet :
void main()
{
int a=100;
int b=200;
char str[10];
int x;
itoa(64,str,16);
printf("%s ",str);
}
Give the output of the following code snippet :
#include< stdio.h>
int main()
{
#define VAR 10
typedef int iptr;
static iptr *ptr,*qtr;
int *rptr;
int x=VAR;
int y=200;
ptr=&x;
qtr=&y;
printf("%d",(*ptr)+(*qtr));
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
}*head=0;
void display(struct node *r)
{
r=head;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
}
void add( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
head=temp;
}
int Delete(int num)
{
struct node *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=temp->next;
free(temp);
return 1;
}
else
{
prev->next=temp->next;
free(temp);
return 1;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return 0;
}
void main()
{
struct node *n;
add(100);
add(200);
display(n);
add(300);
Delete(100);
Delete(200);
display(n);
}
Give the output of the following code snippet :
typedef struct stud *ptr;
struct stud
{
int no;
int no2;
ptr link;
};
void main()
{
stud s;
s.no=10;
printf("%d",s.no);
}
Give the output of the following code snippet :
int main()
{
int y=100;
const int* z=&y;
y+=1;
printf("%d",*z);
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 5;
_asm
{
Label2: cmp dword ptr[i], 5
jl Label1
jmp Label2
Label1 : mov eax, dword ptr[j]
imul eax, dword ptr[j]
add eax, dword ptr[a]
mov dword ptr[a], eax
mov ecx, dword ptr[a]
sub ecx, 1
mov dword ptr[a], ecx
mov edx, dword ptr[j]
add edx, 1
mov dword ptr[j], edx
mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
}
printf("%d", a);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
void func(struct point*);
int main()
{
struct point p1 = {1, 2};
func(&p1);
}
void func(struct point *p)
{
printf("%d\n", p.x++);
}
Give the output of the following code snippet :
void f(int a[][2])
{
a[0][1] = 3;
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
printf("%d ", a[i][j]);
}
void main()
{
int a[2][2] = {0};
f(a);
}
Give the output of the following code snippet :
void main()
{
typedef char* ptr;
char fptr=100;
ptr=&fptr;
printf("%d",*ptr);
}
Give the output of the following code snippet :
void main()
{
double a=100.25;
double b=200.25;
double c = ((a) == (b) ? (a) : (b));
double d= ((a) >= (b) ? (a) : (b));
printf("%.2f %.2f",c,d);
}
Give the output of the following code snippet :
void main()
{
struct student
{
int age;
int id;
};
struct student s= {20,1001};
int ch;
char str[10];
FILE *fp,*fp1;
fp=fopen("Test.txt","w");
fwrite(&s,sizeof(s),1,fp);
fclose(fp);
fp1=fopen("Test.txt","r");
struct student s1;
fread(&s1, sizeof(s1), 1, fp1);
printf("%d",s1.age);
fclose(fp1);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c 100 200 300
int main(int argc, char *argv[])
{
int i=strlen(argv[3]);
int sum=0;
do
printf("%d ",atoi(argv[--argc])+atoi(argv[--argc])-atoi(argv[argc]));
while(!argc);
}
Give the output of the following code snippet :
struct node
{
int x;
struct node *next;
}*Head;
void ReverseList()
{
node *temp1,*temp2,*temp3;
temp1=Head;
temp2=NULL;
while(temp1!=NULL)
{
temp3=temp2;
temp2=temp1;
temp1=temp1->next;
temp2->next=temp3;
}
Head=temp2;
}
void AddNode( int num )
{
struct node *temp,*temp2;
if(Head==NULL)
{
temp2=(struct node *)malloc(sizeof(struct node));
temp2->x=num;
temp2->next=NULL;
Head=temp2;
}
else
temp=Head;
while(temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->x=num;
temp2->next=NULL;
temp->next=temp2;
}
void Display()
{
struct node *r;
r=Head->next;
while(r->next!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(100);
AddNode(200);
Display();
ReverseList();
Display();
}
Give the output of the following code snippet :
void main()
{
char *str1="%s";
char str[]="Hello World";
printf(str1,"Hello");
}
Give the output of the following code snippet :
int main()
{
int (*p)[5];
int a[][5]= {1,2,3,4,5,6};
p=a;
int *q;
q=(int*)a;
printf("%d %d",**p+3,**q+5);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b =0, c=0;
__asm
{
push 100
push 200
push 500
mov ebx,300
mov eax, 400
call label1
add esp, 12
jmp Label2
label1:
mov eax, dword ptr[esp + 4]
mov a, eax
mov eax, dword ptr[esp + 8]
mov b, eax
mov eax, dword ptr[esp + 12]
add eax,ebx
mov c,eax
ret
}
Label2:
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
void main()
{
int a=10,c=20,b=30;
_asm
{
mov eax,dword ptr[a]
mov ebx,dword ptr[c]
cmp eax,ebx
jge Label2
shl eax,1
xor eax,b
mov b,eax
Label2:
mov ecx,a
sub ecx,ebx
jz Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void main()
{
int a=20,c=50,b=20;
_asm
{
mov eax,20
mov ebx,b
cmp eax,dword ptr[c]
jg Label2
mov edx,dword ptr[b]
and edx,eax
mov b,edx
Label2:
mov ecx,dword ptr[a]
cmp ecx,ebx
jne Label1
add eax,ecx
or eax,edx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
struct node
{
int x;
struct node *next;
}*Head;
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x < temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
void AddNode( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->x=num;
temp->next=Head;
Head=temp;
}
void Display()
{
struct node *r;
r=Head;
while(r->next!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(20);
AddNode(3);
AddNode(100);
AddNode(50);
SortList();
Display();
}
Give the output of the following code snippet :
void main()
{
char *str="100.25";
char *str2="200.25";
int x;
x=atoi(str)+atoi(str2);
printf("%d",x);
}
Files Test1.c, Test1.h, Test2.c, Test2.h and Test3.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
void func1();
/* Test2.h */
static int value;
void func();
/* Test1.c */
#include"Test2.h"
void func()
{
printf("Output = %d\n",value);
}
/* Test2.c */
#include"Test2.h"
void func1()
{
printf ( "Output = %d\n", ++value );
func();
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
void main ()
{
func();
}
Give the output of the following code snippet :
void main()
{
int a=40,c=30,b=20;
_asm
{
mov eax,10
mov ebx,dword ptr[c]
cmp eax,ebx
jnl Label2
shl eax,1
and eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
js Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b =0, c=0,d=0;
__asm
{
push 10
push 20
mov ebx,30
mov eax, 40
mov ecx,60
push 50
call label1
add esp, 12
jmp Label2
label1:
mov d,eax
mov eax, dword ptr[esp + 4]
mov a, eax
add a, ebx
mov eax, dword ptr[esp + 8]
mov b, eax
mov eax, dword ptr[esp + 12]
and ebx,ecx
or edx,ecx
mov c,eax
mov d,edx
ret
}
Label2:
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
int main()
{
int ary[4] = {1, 2, 3, 4};
int p[4];
*p = ary[0];
printf("%d\n", p[0]);
}
Give the output of the following code snippet :
struct Vehicle
{
int Id;
char *name;
struct Car
{
int Id;
char *name;
} Cobj;
};
void main()
{
struct Vehicle Vobj[5];
Vobj[0].Cobj.Id=1001;
printf("%d",Vobj[0].Cobj.Id);
}
Give the output of the following code snippet:
int main()
{
char *arg[] = { "ab", "cd", "ef", "gh", "ij", "kl" };
printf("%c", **arg);
}
Give the output of the following code snippet :
#define row 3
#define col 3
void main()
{
int (*arr)[col];
arr=(int (*)[col])malloc(sizeof(row*sizeof(*arr)));
printf("%d",sizeof(arr));
free(arr);
}
Give the output of the following code snippet :
union p
{
unsigned int x : 3;
unsigned int y : 3;
};
int main()
{
union p p;
p.x = 2;
p.y = 4;
printf("%d %d",p.x, p.y);
}
Give the output of the following code snippet :
struct student
{
int mark1;
char *name1;
};
void main()
{
struct student stud;
stud.mark1=100;
stud.name1="Jenn";
struct student s=&stud;
printf("%s",s->name1);
}
Consider the given statement from the below lines of code: What does it indicate?
Head=root;
struct node *root;
root = (struct node *) malloc( sizeof(struct node) );
root->next = 0;
root->x = 5;
Head=root;
Give the output of the following code snippet :
int main()
{
enum days {Mon=-1, Tue, Wed=6, Thu, Fri, Sat,Sun};
printf("%d",Tue);
return 0;
}
Give the output of the following code snippet :
void print(int num,...)
{
int i,k;
float j;
va_list marker;
va_start(marker,num);
j=va_arg(marker,double);
printf("%.2f ",j);
va_end(marker);
}
int main(int argc, char *argv[])
{
print(10,2.2,3.3,4.4);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
struct node *prev;
}*head;
void func( int num )
{
struct node *temp,*temp2;
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
temp->prev=NULL;
head=temp;
}
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
temp2->prev=temp;
}
}
void Delete(int num)
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=head->next;
head->prev=NULL;
}
else
{
if(temp->next==NULL)
temp->prev->next=NULL;
else
{
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
}
}
free(temp);
return;
}
temp= temp->next;
}
}
void display()
{
struct node *r;
r=head;
while(r->next!=NULL)
r=r->next;
while(r->prev!=NULL)
{
printf("%d ",r->data);
r=r->prev;
}
printf("\n");
}
void main()
{
func(100);
func(200);
func(300);
func(400);
Delete(100);
Delete(300);
func(500);
display();
}
Give the output of the following code snippet :
void main()
{
int i = 10, k = 10, j = 2;
int *ary[2];
ary[0] = i;
ary[1] = j;
printf("%d\n", *ary[0]);
}
Give the output of the following code snippet :
float *func()
{
float *s;
s=(float*)malloc(1*sizeof(float));
*s=100.25;
return s;
}
void main()
{
float *s;
s=func();
printf("%.3f",*s);
}
Give the output of the following code snippet :
int main()
{
enum state {working, failed};
enum result {failed, passed};
printf("%d",failed);
}
Give the output of the following code snippet :
int func()
{
int *ptr;
int x=100;
ptr=&x;
return *ptr;
}
void main()
{
int (*f[5])();
f[0]=func;
printf("%d",(*f[0])());
}
Give the output of the following code snippet :
typedef struct stud
{
int no;
int no2;
studobj *link;
} studobj;
void main()
{
studobj s=(studobj *)malloc(sizeof(struct studobj));
s->no=10;
printf("%d",s->no);
}
Give the output of the following code snippet :
int func()
{
int *ptr;
int x=100;
ptr=&x;
return *ptr;
}
void main()
{
int (*f[5])();
f[1]=func;
printf("%d",(*f)());
}
Give the output of the following code snippet :
void func(char *s)
{
char *ptr;
ptr=s;
printf("%s",ptr);
}
void main()
{
char str[];
func(str);
}
Give the output of the following code snippet :
typedef struct student
{
char *a;
} stud;
void main()
{
struct s;
s.a = "Hello";
printf("%s", s.a);
}
Files Test1.c, Test1.h, Test2.c and Test3.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
extern int value;
void func();
void func1();
/* Test1.c */
#include "Test1.h"
int value = 300;
void func()
{
value=200;
printf ( "Output = %d\n", ++value );
func1();
}
/* Test2.c */
#include "Test1.h"
int value;
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=0;
_asm
{
mov eax,20
mov ebx,a
cmp eax,ebx
je Label2
mov b,eax
Label2:
mov ecx,c
and eax,ecx
mov c,eax
}
printf("%d %d",b,c);
}
Give the output of the following code snippet :
void main()
{
int a=-20,c=10,b=30;
_asm
{
mov eax,-20
mov ebx,a
sub eax,ebx
jnz Label2
mov b,45
Label2:
mov ecx,dword ptr[a]
and eax,ecx
jz Label1
xor eax,dword ptr[c]
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int Mult(int first,...)
{
int prod=1, count=0,i=first;
int marker;
va_start(marker,first);
while(i!=0)
{
prod*=i;
count++;
i=va_arg(marker,int);
}
va_end(marker);
return prod;
}
int main(int argc, char *argv[])
{
printf("%d",Mult(2,3,0));
}
Consider the given statement from the below lines of code: What does it indicate?
root->prev=NULL;
struct node *root;
root = (struct node *) malloc( sizeof(struct node) );
root->next = NULL;
root->x = 5;
root->prev=NULL;
Head=root;
Give the output of the following code snippet :
struct student
{
char *name;
};
struct student fun(void)
{
struct student s;
s.name = "Jenn";
return s;
}
void main()
{
struct student m = fun();
s.name = "Ally";
printf("%s", m.name);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax, a
mov ebx, b
add eax, ebx
mov c, eax
}
printf("%d", c);
}
Give the output of the following code snippet : What are the contents of the file 'Test.txt' after the code is executed?
void main()
{
char x;
FILE *fp;
fp=fopen("Test.txt","w+");
fprintf(fp,"%s %s","Hello","World");
fclose(fp);
}
Give the output of the following code snippet :
int main()
{
int x=100,y=100;
int z = x++ || y++;
int a= --z || ++y && x--;
int b=a+(10,20,30,0);
printf("%d %d",b,a);
}
Give the output of the following code snippet :
typedef struct stud s;
void func(struct stud *stuobj);
struct stud
{
int no;
int no2;
s *link;
};
void main()
{
struct stud s= {10,20};
func(&s);
}
void func(struct stud *stuobj)
{
struct stud *s;
s=stuobj;
printf("%d",s->no);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 100;
void func();
/* Test1.c */
extern int value;
void func()
{
printf ( "Output = %d", value );
}
/* Test2.c */
#include "Test1.h"
void main ()
{
extern int value;
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b =0, c=0;
__asm
{
push 100
push 200
mov ebx,300
mov eax, 400
call label1
add esp, 8
jmp Label2
label1:
mov eax, dword ptr[esp + 4]
mov a, eax
mov eax, dword ptr[esp + 8]
mov b, eax
mov eax, dword ptr[esp + 12]
mov c,ebx
ret
}
Label2:
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
int main()
{
float x=0.3,y=10,z=20;
if( x > 0.3)
printf("%.2f",y+z);
else
printf("%.2f",z-y);
}
Give the output of the following code snippet :
int main()
{
int*ptr;
int val=10;
ptr=&val;
printf("%d",*ptr);
}
Give the output of the following code snippet :
void main()
{
int i = 13, a = 10;
_asm
{
mov eax, dword ptr[i]
and eax, 80000001h
jns Label1
dec eax
or eax, 0FFFFFFFEh
inc eax
Label1 : test eax, eax
jne Label2
mov dword ptr[a], 12Ch
}
Label2: printf("%d", a);
}
Give the output of the following code snippet :
void main()
{
int x=10,y=20;
int z=x+y;
const int* ptr=&z;
ptr=&x;
x++;
(*ptr)++;
printf("%d",*ptr);
}
Which of the following are valid pointer operations in C?
< NIL>
Give the output of the following code snippet :
void main()
{
int a[10][10];
int b=sizeof(a);
printf("%d",b);
}
Give the output of the following code snippet :
void func(int i)
{
void *j;
j=&i;
printf("%d",*j);
}
void main()
{
int x=10;
func(x);
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 5;
_asm
{
Label2: cmp dword ptr[i], 5
je Label1
mov eax, dword ptr[j]
imul eax, dword ptr[j]
add eax, dword ptr[a]
mov dword ptr[a], eax
mov ecx, dword ptr[a]
sub ecx, 1
mov dword ptr[a], ecx
mov edx, dword ptr[j]
add edx, 1
mov dword ptr[j], edx
mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
jmp Label2
}
Label1:
printf("%d", a);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b =0, c=0;
__asm
{
push 10
push 20
mov ebx,30
mov eax, 40
mov ecx,label1
call ecx
add esp, 8
mov edx,Label2
mov dword ptr[c],edx
jmp dword ptr[c]
label1:
mov eax, dword ptr[esp + 4]
mov a, eax
mov eax, dword ptr[esp + 8]
mov b, eax
mov eax, dword ptr[esp + 12]
mov c,ebx
ret
Label2:mov c,ebx
}
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
char *func(unsigned int num,int base)
{
static char bffer[33];
char *p=&bffer[sizeof(bffer)-1];
*p='\0';
do
{
*--p="0123456789"[num%base];
num/=base;
}
while(num!=0);
return p;
}
void main()
{
char *str;
str=func(9,8);
printf("%s",str);
}
Give the output of the following code snippet :
void main()
{
int x = 0;
int *ptr = &x;
printf("%d ", *ptr);
x++;
printf("%d ", *ptr);
}
Give the output of the following code snippet :
int main()
{
int ary[2][3];
int j = 20;
*ary[0] = j;
printf("%d\n", *ary[0]);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c 100 200 300
int main(int argc, char *argv[])
{
int i=strlen(argv[3]);
int sum=0;
do
printf("%d ",atoi(argv[--argc])+atoi(argv[--argc])+atoi(argv[argc]));
while(argc);
}
Give the output of the following code snippet :
int Mult(int first,...)
{
int prod=0, count=0,i=first;
va_list marker;
va_start(marker,first);
while(i!=0)
{
prod*=i;
count++;
i=va_arg(marker,int);
}
va_end(marker);
return prod;
}
int main(int argc, char *argv[])
{
printf("%d",Mult(2,3,0));
}
Give the output of the following code snippet :
#define row 2
#define col 2
void main()
{
int (*arr)[col];
arr=(int (*)[col])malloc(sizeof(row*sizeof(*arr)));
for(int i=0; i< row; i++)
for(int j=0; i< col; i++)
arr[i][j]=i+j;
for(int i=0; i< col+row-1; i++)
printf("%d ",*arr[i]+1);
}
Give the output of the following code snippet :
int main()
{
int a = 1;
_asm
{
mov eax, dword ptr[a]
mov dword ptr[ebp - 0D0h], eax
cmp dword ptr[ebp - 0D0h], 1
je Label1
cmp dword ptr[ebp - 0D0h], 2
je Label2
cmp dword ptr[ebp - 0D0h], 3
je Label3
jmp Label4
Label1 : mov dword ptr[a], 2
Label2 : mov dword ptr[a], 3
jmp Label4
Label3 : mov eax, dword ptr[a]
add eax, 4
mov dword ptr[a], eax
}
Label4 : printf("%d", a);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20,c=5;
_asm
{
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
or ebx,c
mov ecx,eax
and ecx,ebx
mov dword ptr[c],ecx
}
printf("%d",c);
}
Give the output of the following code snippet :
int main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d", *ptr, a);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c 100 200 300
int main(int argc, char *argv[])
{
for(int i=0; i< argc; i++)
printf("%d ", atoi(argv[i]));
return 0;
}
Give the output of the following code snippet :
void main()
{
char s1[]="Hello";
char *s2=(char*)malloc(sizeof(s1));
int b=200;
char str[20];
sprintf(s2,"%.*s",8,s1);
puts(s2);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c Hello World Program
int main(int argc, char *argv[])
{
int i=strlen(argv[3]);
int sum=0;
printf("%c %d",argv[2][i],i);
}
Give the output of the following code snippet :
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
} p;
int x;
};
int main()
{
union u u1 = {2};
printf("%d\n", u1.p.y);
}
Give the output of the following code snippet :
int sum(int x,int y)
{
return x+y;
}
void main()
{
int (*fptr)(int a,int b);
fptr = sum;
printf("%d",(fptr)(10,20));
}
Give the output of the following code snippet :
void main()
{
int *ptr,a[6]= {1,2,3,4,5,6};
int i;
ptr=(int*)calloc(6,sizeof(int));
for(i=0; i< 6; i++)
{
printf("%d ",*ptr+a[i]);
}
}
Give the output of the following code snippet :
struct node
{
int x;
struct node *next;
}*Head;
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
void AddNode( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->x=num;
temp->next=Head;
Head=temp;
}
void Display()
{
struct node *r;
r=Head;
while(r!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(20);
SortList();
Display();
}
Give the output of the following code snippet :
union date
{
unsigned int d;
unsigned int m;
unsigned int y;
};
int main()
{
union date dt= {12, 10, 2000};
printf("Date is %d/%d/%d", dt[0].d, dt[0].m, dt[0].y);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
void fun(struct point*);
int main()
{
struct point p1 = {1, 2};
fun(&p1);
}
void fun(struct point *p)
{
printf("%d\n", p -> x++);
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=30;
_asm
{
mov eax,20
mov ebx,a
add eax,dword ptr[c]
jz Label2
mov b,eax
Label2:
mov ecx,c
cmp eax,ecx
jns Label1
and eax,dword ptr[b]
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
typedef struct stud *ptr;
typedef struct emp *qtr;
struct stud
{
int no;
int no2;
struct emp *link;
};
struct emp
{
int id;
struct stud *link2;
};
void main()
{
ptr s=(stud *)malloc(sizeof(struct stud));
s->no=10;
printf("%d",s->no);
}
Give the output of the following code snippet :
int sum(int x,int y)
{
return x+y;
}
void main()
{
int (*fptr)(int,int);
fptr = sum;
printf("%d",(fptr)(10,20));
}
Give the output of the following code snippet :
void main()
{
int y,z;
int x=printf("%d HelloWorld\n");
printf("%d",x);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b =0, c=0,d=0;
__asm
{
push 100
push 200
push 500
mov ebx,300
mov eax, 400
mov ecx,600
call label1
add esp, 12
jmp Label2
label1:
mov d,eax
mov eax, dword ptr[esp + 4]
mov a, eax
mov eax, dword ptr[esp + 8]
mov b, eax
mov eax, dword ptr[esp + 12]
sub eax,ebx
and ebx,ecx
mov c,eax
mov d,ebx
ret
}
Label2:
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
int main()
{
typedef char char_arry[6];
char_arry arry= {10,20,30,'a','b','c'};
int i=0;
while(i!=6)
{
printf("%d ",*(arry+i)+2);
i+=2;
}
}
Give the output of the following code snippet :
struct node
{
int x;
struct node *next;
}*Head;
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
void AddNode( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->x=num;
temp->next=Head;
Head=temp;
}
void Display()
{
struct node *r;
r=Head;
while(r!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(20);
AddNode(3);
Display();
SortList();
Display();
}
Give the output of the following code snippet :
struct temp
{
int a;
} s;
void change(struct temp s)
{
s.a = 1;
}
void main()
{
s.a = 10;
change(s);
printf("%d\n", s.a);
}
Give the output of the following code snippet :
typedef struct stud
{
int no;
int no2;
stud *link;
} stud;
void main()
{
stud s;
s.no=1001;
printf("%d",s.no);
}
Give the output of the following code snippet :
int main()
{
char *s;
char buf [] = "Hello World";
s = strchr (buf, 'l');
if (s != NULL)
printf ("Found %s", s);
else
printf("Not found");
return 0;
}
Give the output of the following code snippet :
void main()
{
int ch=0,sum=0,i;
int num=3;
for (i=0; i< 4; i++)
{
printf("%d",(num << i & 1 << 3)? 0 : 1);
}
}
Give the output of the following code snippet :
int main()
{
int arry[5]= {20};
arry[5]=10;
arry[6]=++(*arry);
printf("%d",5[arry]);
}
Give the output of the following code snippet :
int main()
{
int a[4] = {1, 2, 3, 4},n=0;
int *p = &a[1];
int *ptr = &a[2];
n = ptr - p;
printf("%d\n", n);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
void func()
{
int value = 200;
printf ( "Output = %d\n", value );
}
/* Test1.c */
void func();
/* Test2.c */
#include"Test1.h"
static int value = 100;
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
typedef int(*fptr)(int a);
typedef struct
{
int a;
fptr fpt[10];
} fp;
int fun(int a)
{
int sum = 0;
_asm
{
mov eax, dword ptr[a]
or eax, 30h
mov ecx, dword ptr[sum]
shl ecx,1
or ecx,dword ptr[a]
mov dword ptr[sum], ecx
}
printf("%d", sum);
return 0;
}
int _tmain()
{
fp myS;
myS.fpt[1] = fun;
_asm
{
push 48h
mov ecx, 4
shl ecx, 0
mov edx, dword ptr[ebp + ecx - 28h]
call edx
add esp, 4
}
}
Give the output of the following code snippet :
typedef struct Node
{
int data;
struct Node *next;
} node;
node *HeadNode=0;
void print(node *pointer)
{
if(pointer==NULL)
return;
printf("%d ",pointer->data);
print(pointer->next);
}
void main()
{
node *start;
start = (node *)malloc(sizeof(node));
start -> data=100;
start -> next = NULL;
HeadNode=start;
start = (node *)malloc(sizeof(node));
start -> data=200;
start -> next = NULL;
HeadNode->next=start;
start = (node *)malloc(sizeof(node));
start -> data=300;
start -> next = NULL;
HeadNode->next->next=start;
print(start);
}
Give the output of the following code snippet :
void func(float);
void (*fptr)(float) = func;
int main()
{
fptr(10);
}
void func(float i)
{
printf("%.1f ", i);
}
Give the output of the following code snippet :
struct temp
{
int a;
int b;
int c;
} p[] = {10,20,3};
void main()
{
printf("%d", sizeof(p));
}
Give the output of the following code snippet :
int main()
{
int i = 10;
int *p = &i;
printf("%f\n", *(float*)p);
return 0;
}
Give the output of the following code snippet :
int sum(char* first,...)
{
int sum=0, count=0,i;
va_list marker;
do
{
i=va_arg(marker,int);
printf("%d ",i);
}
while(i!=0);
va_end(marker);
return sum;
}
int main(int argc, char *argv[])
{
sum("Test",2,4,6,-1);
}
Give the output of the following code snippet :
struct node
{
int x;
struct node *next;
}*Head;
void ReverseList()
{
node *temp1,*temp2,*temp3;
temp1=Head;
temp2=NULL;
while(temp1!=NULL)
{
temp3=temp2;
temp2=temp1;
temp1=temp1->next;
temp2->next=temp3;
}
Head=temp2;
}
void AddNode( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->x=num;
temp->next=Head;
Head=temp;
}
void Display()
{
struct node *r;
r=Head;
while(r->next!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(100);
AddNode(200);
ReverseList();
Display();
}
Consider the given lines of code : What does the line below signify?
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
}
void add( int num )
{
struct node *temp,*temp2;
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
head=temp;
}
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
}
}
Give the output of the following code snippet :
int main()
{
char *MemAlloc;
MemAlloc = (char*)malloc(20 * sizeof(char) );
strcpy( MemAlloc,"SourceLens");
printf("%d",MemAlloc);
}
Give the output of the following code snippet :
void main()
{
char *s1="Hello";
char *s2="World";
int b=200;
float a=100.25;
char str[20];
sprintf(str,"%d",a+b);
puts(str);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax, a, b
sub eax, ebx
mov c, eax
}
printf("%d", c);
}
Give the output of the following code snippet :
#define CONCAT(x,y,z) printf("%s %s %s",x,y,z);
int main()
{
char *str1="Hello";
char *str2="World";
char *str3="Program";
CONCAT(str1,str2,str3);
}
Give the output of the following code snippet run with the following commandline arguments:
>Testfile.c Yellow Jello
/* Testfile.c */
int main(int argc, char *argv[])
{
int i;
for(i=1; i< argc; i++)
printf("%s ", *(argv+1));
return 0;
}
Give the output of the following code snippet :
void main()
{
char a[10][6] = {"Hola","Hello","Jello"};
printf("%s", *a+3);
}
Give the output of the following code snippet :
void main()
{
FILE *fp,*fp1;
char x;
fp = fopen("Test.txt","w+");
fputs("Hello World Program", fp);
fseek( fp, 10, SEEK_SET );
fputs("Yello", fp);
fclose(fp);
fp1 = fopen("Test.txt","r");
while(1)
{
x = fgetc(fp);
if( feof(fp) )
{
break;
}
printf("%c", x);
}
fclose(fp1);
}
Give the output of the following code snippet :
void main()
{
int a[10] = {1};
printf("%d %d", sizeof(a),*a);
};
Give the output of the following code snippet :
int main()
{
int (*p)[5];
int a[][5]= {1,2,3,4,5,6};
p=a;
int *q;
q=(int*)a;
printf("%d %d",**p+3,*q+5);
}
Give the output of the following code snippet :
void main()
{
double a=100.25;
double b=200.25;
double c = ((a) = (b) ? (a) : (b));
double d= ((a) >= (b) ? (a) : (b));
printf("%.2f %.2f",c,d);
}
What do the following lines of code indicate?
if(temp==head)
{
head=temp->next;
free(temp);
}
int Delete(int num)
{
struct node *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=temp->next;
free(temp);
return 1;
}
else
{
prev->next=temp->next;
free(temp);
return 1;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return 0;
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b =0, c=0;
__asm
{
push 100
push 200
mov ebx,300
mov eax, 400
call label1
add esp, 8
jmp Label2
label1:
mov eax, dword ptr[esp + 4]
mov a, eax
mov eax, dword ptr[esp + 8]
mov b, eax
mov eax, dword ptr[esp + 12]
add eax,ebx
mov c,eax
ret
}
Label2:
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
int mod(int a, int b)
{
return a % b;
}
void main()
{
int (*fptr)( int,int)= &mod;
printf("%d",(*fptr)(10,6));
}