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 :
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!=NULL)
{
printf("%d ",r->data);
r=r->next->next;
}
}
void main()
{
func(100);
func(200);
func(300);
func(400);
display();
}
Give the output of the following code snippet :
struct student
{
char a[10];
};
void main()
{
struct student s[] = {"Hello", "World"};
printf("%d", sizeof(s));
}
What is the output of the following code snippet if it is run with no commandline arguments?
int main(int argc, char *argv[])
{
printf("%d\n", argc);
return 0;
}
If pointers p and q point to members of the same array, then which of the following relations are legal?
< NIL>
Give the output of the following code snippet :
void main()
{
struct temp
{
char c;
float d;
};
struct temp2
{
int a[3];
char b;
struct temp t1;
};
struct temp2 st = {{1,2,3},'P','q',1.4};
printf("%d %c %c %f",st.a[1],st.b,t1.c,t1.d);
getch();
}
Give the output of the following code snippet :
int main()
{
int i, *j, k;
_asm
{
mov dword ptr[i], 0Bh
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov eax, dword ptr[i]
add eax, dword ptr[ecx]
add ecx, dword ptr[i]
mov ecx, dword ptr[j]
cdq
imul dword ptr[ecx]
add eax, dword ptr[i]
mov dword ptr[k], eax
}
printf("%d\n", k);
return 0;
}
Give the output of the following code snippet :
int main()
{
int *Pa1=0;
int *Pa2=0;
int *Pa3;
int a=10,b=20;
Pa1=a;
Pa2=b;
*Pa3=*Pa1**Pa2;
printf("%d",*Pa3);
}
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 :
struct Test
{
static int x: 2;
int y[10]:2;
} t;
void main()
{
t.x=10;
t.y=20;
printf("%d",t.y);
}
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;
j=va_arg(marker,int);
for(i=0; i< num; i++)
printf("%d ",j);
va_end(marker);
}
int main(int argc, char *argv[])
{
disp(3,10,20,30);
}
Give the output of the following code snippet :
int main()
{
int ary[4] = {1, 2, 3, 4};
int *p = ary + 3;
printf("%d\n", p[-2]);
}
Give the output of the following code snippet :
void print(char* first,...)
{
int sum=0, count=0,i;
char* marker;
va_start(marker,first);
do
{
i=va_arg(marker,int);
printf("%d ",i);
}
while(i!=6);
va_end(marker);
}
int main(int argc, char *argv[])
{
print("Test",2,4,'D',-1);
}
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]
and ebx,c
mov ecx,10
or ecx,ebx
mov c,ecx
}
printf("%d",c);
}
Give the output of the following code snippet :
void main()
{
int x = 1, y = 0, z = 5;
int a = x & y || z ^ y;
printf("%d", 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"
void func1()
{
value=200;
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
int value = 400;
void main ()
{
func1();
printf("Output = %d",value);
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=30;
_asm
{
mov eax,30
mov ebx,a
xor eax,dword ptr[c]
jz Label2
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
js Label1
and eax,dword ptr[b]
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 5;
_asm
{
Label1: mov eax, dword ptr[a]
add eax, dword ptr[j]
mov dword ptr[a], eax
mov ecx, dword ptr[i]
add ecx, 1
mov dword ptr[i], ecx
xor edx, edx
jne Label1
}
printf("%d", a);
}
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 */
static int value;
void func1();
/* Test2.h */
extern int value;
void func();
/* Test1.c */
#include "Test1.h"
void func()
{
printf("Output = %d\n",value);
}
/* Test2.c */
#include "Test1.h"
int value = 200;
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
void main()
{
char *s= "hello";
char *p = s;
printf("%d %d", p[1], *s[1]);
}
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[2]);
int sum=0;
while(i>=0)
{
printf("%c",argv[2][i]);
i--;
}
}
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]=y+++(++x);
printf("%d ",arr[i]+x++);
}
}
Give the output of the following code snippet :
union stud
{
int age;
int id;
};
void main()
{
union stud s= {20,1001};
union stud *temp=(stud*)malloc(sizeof(stud));
temp=&s;
temp->id=30;
printf("%d",temp->age);
}
Give the output of the following code snippet :
int main()
{
union var
{
int a;
};
union var v[10];
v[0].a=10;
v[1].a=20;
printf("%d\n", v[0].a);
return 0;
}
Give the output of the following code snippet :
union Test
{
char str[20];
};
int main()
{
union Test st1, st2;
strcpy(st1.str, "Hello");
st2 = st1;
st1.str[0] = 'J';
st2.str[0] = 'Y';
printf("%s",st1.str);
}
Give the output of the following code snippet :
void main()
{
int x=10,y=20;
int z=x+y;
int const* ptr=&z;
z++;
printf("%d",*ptr);
}
Give the output of the following code snippet :
typedef void v;
v func(int*);
void main()
{
v *val;
int x=100;
val=&x;
func(val);
}
v func(void *x)
{
printf("%d",*(int*)x);
}
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=x< < 3;
z>>=1;
printf("%d %d %d",x,y,~z);
}
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));
}
What do the following lines of code indicate?
else
{
prev->next=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 : Assume inputs given as 'D' and 10.5
void main()
{
char x,y;
float a;
scanf("%c",&x);
scanf("%f",&a);
printf("%c %f",x,a);
}
Give the output of the following code snippet :
void main()
{
int a= 10,*ptr;
ptr=(int*)calloc(a*sizeof(int));
ptr=&a;
printf("%d",*ptr);
}
Give the output of the following code snippet :
void main()
{
char str[10]="Hello";
char *str2;
str2="World";
strcat(str,str2);
printf("%s ",str);
}
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->next;
while(r->next!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(20);
Display();
ReverseList();
Display();
}
Give the output of the following code snippet :
void main()
{
int a=100;
int b=200;
char str[10],st[10];
int x;
gcvt(25.3456,2,str);
itoa(100,st,16);
printf("%s %s",str,st);
}
Give the output of the following code snippet :
int main()
{
int ary[4] = {1, 2, 3, 4};
printf("%d\n", *ary);
}
Give the output of the following code snippet :
int main()
{
int a=10, b=20, c,d,e;
c = (a == 100 && b >= 10);
c= a--*a++-b++/--b;
d=a++%b--/c++;
e=d++/c---a++/b;
printf("%d %d %d", c,d,e);
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 = 300;
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void main ()
{
printf ( "Output = %d", value );
}
Give the output of the following code snippet :
int(*funcptr) (int a);
int myfunc(int a)
{
int sum=0;
_asm
{
mov dword ptr [a],0Eh
mov eax,dword ptr [sum]
add eax,dword ptr [a]
mov dword ptr [sum],eax
mov ecx,dword ptr [a]
imul ecx
mov dword ptr [a],ecx
}
printf("%d",a);
return 0;
}
int testCaller(int(*funcptr) (int a))
{
_asm
{
push 32h
call dword ptr [funcptr]
add esp,4
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
testCaller(myfunc);
return 0;
}
Give the output of the following code snippet :
int main()
{
int *Pa1 = 0;
int *Pa2 = 0;
int *Pa3 = 0;
int c = 0;
int a, b;
_asm
{
mov dword ptr[a], 0Ah
mov dword ptr[b], 14h
lea eax, [a]
mov dword ptr[Pa1], eax
lea ecx, [b]
mov dword ptr[Pa2], ecx
mov edx, dword ptr[Pa1]
mov eax, dword ptr[edx]
mov ecx, dword ptr[Pa2]
add eax, dword ptr[ecx]
mov dword ptr[c], eax
lea edx, [c]
mov dword ptr[Pa3], edx
}
printf("%d", *Pa3);
}
Give the output of the following code snippet :
void main()
{
int a = 10, b = 0, c;
_asm
{
cmp dword ptr[a], 32h
jg Label1
mov dword ptr[b], 14h
mov dword ptr[c], 1Eh
jmp Label2
Label1 : mov dword ptr[b], 28h
mov dword ptr[c], 32h
Label2 :
}
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
int main()
{
float x=10.00;
double y=10;
if( x == y)
printf("%.2e %f",x,x);
else
printf("%g %f",y,y);
}
Give the output of the following code snippet :
void main()
{
int x=10,y=20;
int z=x+y;
const int* ptr=&z;
z++;
printf("%d",*ptr);
}
Give the output of the following code snippet :
void main()
{
int a=30,c=-10,b=20;
_asm
{
mov eax,40
mov ebx,b
sub eax,dword ptr[b]
jo Label2
mov edx,dword ptr[c]
and edx,eax
mov b,edx
Label2:
mov ecx,dword ptr[a]
mov ebx,10
cmp ecx,ebx
je Label1
add eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
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 = 300;
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
int sum1(int x,int y)
{
return x+y;
}
void main()
{
int (*fptr)(int a,int b);
fptr = &sum1;
printf("%d",(*fptr)(10,20));
}
Predict the output of the following code snippet :
void func( int num )
{
struct node *temp,*temp2;
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 main()
{
func(100);
func(200);
func(300);
func(400);
func(500);
display();
}
Give the output of the following code snippet :
void main()
{
int a=2,b=3,c=4;
unsigned int d=2;
int x=1,y=2,z=30;
x= a || b & c ;
y = x | 2 & b;
printf("%d %d %d",x,y,-2 < < ~2);
}
Give the output of the following code snippet :
void main()
{
char a[10][6] = {"Hola","Hello","Jello"};
printf("%s", a+1);
}
Give the output of the following code snippet :
char *func()
{
char *str;
strcpy(str,"Hello World");
return str;
}
void main()
{
char *s;
s=func();
printf("%s",s);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
} p[] = {1, 2, 3, 4, 5};
void fun(struct point*);
int main()
{
fun(p);
}
void fun(struct point p[])
{
printf("%d %d\n", p++->x, ++p[2].y);
}
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 who's solution configuration has been set to the DEBUG mode :
int main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
_asm
{
mov eax, 10
push eax
push 10
push 20
push 30
push 40
mov ebx, dword ptr[esp]
mov a, ebx
mov ebx, dword ptr[esp + 4]
mov b, ebx
mov ebx, dword ptr[esp + 8]
mov c, ebx
mov ebx, dword ptr[esp + 12]
mov d, ebx
}
printf("%d %d", a,b );
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
__asm
{
push 100
push 200
call Func
jmp End
Func :
pop dword ptr[esp]
mov eax, dword ptr[esp]
mov a, eax
pop dword ptr[esp+8]
mov eax, dword ptr[esp + 8]
mov a, eax
ret
End :
}
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet : Assume the array begins at the following address 5000.
int main()
{
int (*p)[5];
int a[][5]= {1,2,3,4,5,6};
p=a;
printf("%u %u",p,a);
}
Give the output of the following code snippet :
#define val 20
void main()
{
int arry[val]= {0};
char str[val];
arry[10]=10;
arry[5]=20;
str[3]='B';
printf("%d %c",arry[10]+arry[5],(str[3]++));
}
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(11111);
}
Give the output of the following code snippet :
int main()
{
float x=0.3,y=10,z=20;
if( x == 0.3f)
printf("%.2f",y+z);
else
printf("%.2f",z-y);
}
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=&p;
printf("%d %d",*a,*b);
}
Give the output of the following code snippet :
struct point
{
int x;
float y;
};
void fun(struct point*);
int main()
{
struct point p1[] = {};
fun(p1);
}
void fun(struct point p[])
{
printf("%d %f\n", p->x, p[3].y);
}
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));
}
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 :
struct student
{
char a[10];
};
void main()
{
struct student s[] = {"Hello", "World"};
printf("%c", s[0].a[1]);
}
Give the output of the following code snippet :
void main()
{
struct student
{
int age;
int id;
};
struct student s= {20,1001,30,1002};
int ch;
char str[10];
FILE *fp,*fp1;
fp=fopen("Test.txt","r");
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 :
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 :
union test
{
int x;
char arr[4];
int y;
};
int main()
{
union test t;
t.x = 0;
t.arr[1] = 'G';
printf("%s", t.arr);
}
Give the output of the following code snippet :
char *func()
{
char *s;
s=(char*)malloc(20*sizeof(char));
strcpy(s,"Hello World");
return s;
}
void main()
{
char *s;
s=func();
printf("%s",s);
}
Give the output of the following code snippet :
int f(int i)
{
_asm
{
mov eax,dword ptr [i]
add eax,6Ah
add eax,0Fh
mov ebx,2Ch
or eax,ebx
mov dword ptr [i],eax
mov eax,dword ptr [i]
}
}
void main()
{
int a;
int(*fptr)(int) = f;
_asm
{
push 0Ah
call dword ptr [fptr]
add esp,4
mov dword ptr [a],eax
}
printf("%d", a);
}
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 :
const int* func(int i)
{
int x=i;
const int *ptr=&x;
return (ptr);
}
void main()
{
int a=10;
const int *qtr=func(a);
printf("%d",*qtr);
}
Give the output of the following code snippet :
void main()
{
const int val=20;
int arry[val]= {0};
char str[val]="Hello World";
arry[10]=10;
arry[5]=20;
str[0]='Y';
printf("%d %s",arry[10]+arry[5],str);
}
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(111);
}
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
mov a,eax
mov b,ebx
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 :
struct student
{
char *name;
};
void func(struct student s)
{
struct student *s1;
s1=&s;
strcpy(s1->name,"Jenn");
printf("%s\t", s1->name);
}
void main()
{
struct student s;
func(s);
}
Consider the given code : When is the given block of code executed?
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
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 :
int main()
{
int i=100,*p,*p1;
p=&i;
p1=p;
printf("%d",*p1);
}
Give the output of the following code snippet :
int main()
{
float x=0.3,y=10.89,z=20.68;
if( x > 0.3)
printf("%.0f",fmod(z,y));
else
printf("%.0f",fmod(y,z));
}
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(i>=0)
{
printf("%c",argv[1][i]);
i--;
}
}
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=(20,30,40)+a+(10,20,30,20);
printf("%d %d",b,a);
}
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(3,2);
printf("%s",str);
}
Give the output of the following code snippet :
void main()
{
int a=20,c=40,b=0,d=5;
_asm
{
mov eax,20
mov ebx,c
cmp eax,ebx
jne Label2
and eax,dword ptr[c]
mov b,eax
Label2:
mov eax,c
cmp eax,dword ptr[d]
mov ebx,100
and eax,ebx
je Label1
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet : Assume the input given is 100.
void main()
{
int i=3;
int x;
while(i!=0)
{
scanf("%d",&x);
ungetc(x,stdout);
printf("%d ",x);
ungetc(x,stdin);
i--;
}
}
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);
}
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();
/* Test1.c */
#include "Test1.h"
void func()
{
value = 200;
}
/* Test2.c */
#include "Test1.h"
int value = 200;
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
char *func()
{
void *str;
str=(char*)malloc(20*sizeof(char));
strcpy(str,"Hello World");
return (char*)str;
}
void main()
{
char *s;
s=func();
printf("%s",s);
}
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);
add(300);
add(400);
Delete(100);
display(n);
}
Give the output of the following code snippet :
struct student
{
char *name;
};
void fun()
{
struct student s;
s.name = "Anne";
printf("%s", s.name);
}
void main()
{
fun();
}
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
push 30
push 40
mov ebx,30
push ebx
mov eax, 40
mov ecx,label1
call ecx
add esp,0x10
mov edx,Label2
mov dword ptr[c],edx
jmp dword ptr[c]
label1:
add esp,4
mov eax, dword ptr[esp + 4]
mov a, eax
pop eax
mov b, eax
pop eax
mov c,eax
mov eax, dword ptr[esp + 8]
mov d,eax
sub esp,12
ret
Label2:mov c,ebx
mov b,eax
}
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 5;
_asm
{
Label3: cmp dword ptr[i], 5
je Label1
mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
cmp dword ptr[i], 3
je Label2
jmp Label3
jmp Label4
Label2 : mov ecx, dword ptr[a]
add ecx, 1
mov dword ptr[a], ecx
Label4 : jmp Label3
}
Label1:
printf("%d", a);
}
Give the output of the following code snippet :
void main()
{
int a=20,c=-10,b=0;
_asm
{
mov eax,20
cmp eax,dword ptr[a]
je Label2
mov b,eax
Label2:
mov ecx,c
mov eax,ecx
cmp eax,dword ptr[c]
js Label1
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
typedef struct
{
int id;
} Test;
int main()
{
Test t1;
t1.id=10;
printf("%d",t1.id);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 10, b = 10,c=0;
__asm
{
mov eax,Label1
mov dword ptr[c],eax
call dword ptr[c]
mov ebx,Label2
mov dword ptr[b],ebx
jmp dword ptr[b]
Label1 :
mov a, 64
ret
Label2 : mov b,100
}
printf("%d %d", a,b);
}
The operator used to get value at address stored in a pointer variable is :
< NIL>
Give the output of the following code snippet :
int main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
_asm
{
mov eax, 10
push eax
mov ebx, 20
push ebx
mov ecx, 30
push ecx
mov edx, 40
push edx
push 100
mov ebx, dword ptr[esp]
mov a, ebx
mov ebx, dword ptr[esp+4]
mov b, ebx
push 200
mov ebx, dword ptr[esp+8]
mov c, ebx
mov ebx, dword ptr[esp+12]
mov d, ebx
add esp, 0x10
}
printf( "%d %d %d %d", a, b, c, d );
}
Give the output of the following code snippet :
void func(int *p)
{
printf("%d\n", *p);
}
int main()
{
int i = 10;
func((&i)++);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20,c=5;
_asm
{
mov eax,a
mov ebx,b
or ebx,c
mov ecx,eax
and ecx,ebx
mov c,ecx
}
printf("%d",c);
}
Give the output of the following code snippet :
void main()
{
int row=2,col=2;
int **arr;
int i,j;
arr=(int**)malloc(row*sizeof(int));
for(i=0; i< row; i++)
arr[i]=(int*)malloc(col*sizeof(int));
for(i=0; i< row; i++)
{
for(j=0; j< col; j++)
{
arr[i][j]=i+j*i;
printf("%d ",arr[i][j]);
}
}
}
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,*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;
while(r!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
SortList();
AddNode(20);
AddNode(3);
AddNode(100);
Display();
}
Give the output of the following code snippet :
int main()
{
struct u
{
unsigned char x : 1;
unsigned int y : 2;
} p;
struct u un;
un.y = 2;
printf("%d\n",un.y);
}
Give the output of the following code snippet :
void main()
{
int x = 0;
int *const ptr = &x;
ptr++;
printf("%p\n ", ptr);
}
Give the output of the following code snippet : Assume the contents of the file 'Test.txt' is "Hello World".
void main()
{
char x;
FILE *fp,*fp1;
fp=fopen("Test.txt","r");
fseek(fp,10,SEEK_SET);
fputc('S',fp);
fclose(fp);
fp1=fopen("Test.txt","r");
while((x=getc(fp1))!=EOF)
{
printf("%c",x);
}
fclose(fp1);
}
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 main()
{
int a,b=2,c=10;
_asm
{
mov dword ptr[a],0
mov eax,dword ptr[c]
mov dword ptr[b],20
add ecx,dword ptr[c]
or ecx,eax
inc ecx
mov a,ecx
}
printf("%d",a);
}
Give the output of the following code snippet :
int main()
{
int arr[5]= {20,10,5,0,1};
int arry2[]= {*arr,*arr+2,*arr+3,*arr+4};
int *p;
p=arry2;
++(*arry2);
++p;
arr[1]=10;
arry2[2]=++(*arr);
printf("%d %d",*p,(*arr)+++(*arry2));
}
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 c,eax
}
printf("%d",c);
}
Give the output of the following code snippet :
int main()
{
int i=10,*p;
p=&i;
(*p)++;
printf("%d",(*p)++);
}
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");
break;
else
printf("World");
}
}
Give the output of the following code snippet
int main()
{
void *p;
int a[4] = {1, 2, 3, 4};
p = &a[3];
int *ptr = &a[2];
int n = p - ptr;
printf("%d\n", n);
}
Give the output of the following code snippet :
const int* func(int i)
{
int x=i;
const int *ptr=&x;
return (ptr);
}
void main()
{
int a=10,b=20;
const int *qtr=func(a);
qtr=&b;
printf("%d",*qtr);
}
Give the output of the following code snippet :
void main()
{
char arry[10]="Hello";
char str[15]="World";
const char* ptr=str;
str[0]='Y';
printf("%s",str);
}
Give the output of the following code snippet :
union u
{
struct p
{
unsigned char x : 2;
unsigned int y : 2;
} p;
int x;
};
int main()
{
union u u;
p.x = 2;
printf("%d\n", p.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(int);
extern int arg = 10;
/* Test2.h */
extern int value;
void func(int);
/* Test1.c */
#include"Test2.h"
void func1(int);
void func(int arg)
{
func1(arg);
value = 200;
printf("Output = %d\n",arg+value);
}
/* Test2.c */
#include"Test2.h"
void func1(int arg)
{
value = 100;
printf ( "Output = %d\n", arg+value );
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
void main ()
{
func1(arg);
}
Give the output of the following code snippet :
typedef struct stud *ptr;
{
int no;
int no2;
ptr link;
};
void main()
{
stud s;
s.no=1001;
printf("%d",s.no);
}
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
jle 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 :
void convertToBinary(int val)
{
for (int c = 7; c >= 0; c--)
{
int k = val >> c;
if (k & 1)
printf("1");
else
printf("0");
}
}
int main()
{
convertToBinary(20);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
int z;
};
int main()
{
int* offset=(((point*)0)->z);
printf("%d",offset);
}
Give the output of the following code snippet :
void main()
{
int x=10,y=20;
int z=x+y;
int* const ptr=&x;
printf("%d",*ptr);
}
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 :
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 :
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 :
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
mov a,eax
mov b,ebx
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]
or ebx,ecx
xor 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 :
void func(struct stud *stuobj);
struct stud
{
int no;
char name[3];
stud *link;
};
void main()
{
struct stud s= {1001,"Jenny"};
func(&s);
}
void func(struct stud *stuobj)
{
struct stud *s;
s=stuobj;
printf("%s",s->name);
}
Give the output of the following code snippet :
int main()
{
int *p = (int *)10;
int *q = (int *)6;
printf("%d", p + q);
}
Give the output of the following code snippet :
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
struct student m;
s.c = m.c = "Hello";
m.point = s;
(m.point)->c = "World";
printf("%s %s", s.c, m.c);
}
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 :
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 :
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(125);
}
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,*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;
while(r->next!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
SortList();
AddNode(20);
AddNode(3);
AddNode(100);
AddNode(50);
Display();
}
Give the output of the following code snippet :
void main()
{
int a[10] = {1};
printf("%d %d", sizeof(a[10]),*a);
};
Give the output of the following code snippet :
void main()
{
char *a[10] = {"hi", "he", "ho"};
int i = 0, j = 0;
a[0] = "hey";
for (i = 0; i < 4; i++)
printf("%s ", a[i]);
}
Give the output of the following code snippet :
int(*funcptr) (int a);
int myfunc(int a)
{
int sum=0;
_asm
{
mov dword ptr [sum],32h
mov dword ptr [a],64h
mov eax,dword ptr [sum]
add eax,dword ptr [a]
mov dword ptr [sum],eax
mov dword ptr [a],eax
}
printf("%d",a);
return 0;
}
int testCaller(int(*funcptr) (int a))
{
_asm
{
push 32h
call dword ptr [funcptr]
add esp,4
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
testCaller(myfunc);
return 0;
}
Give the output of the following code snippet :
struct
{
char *name;
union
{
char *sval;
} u;
} symtab[10];
void main()
{
symtab[0].u.sval="HelloWorld";
printf("%s",symtab[1].u.sval);
}
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;
do
printf("%s ",argv[--argc]);
while(!argc);
}
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 :
int main()
{
int a = 20, b = 10,c=2;
_asm
{
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
push eax
push ebx
mov ecx,dword ptr[c]
pop eax
sub eax,ecx
xor ebx,ecx
inc ebx
mov a,eax
pop ebx
mov b,ebx
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
int main()
{
_asm
{
mov eax,10
mov ebx,20
add eax,ebx
mov dword ptr[a],eax
}
printf("%d",a);
}
Give the output of the following code snippet :
int(*funcptr) (int a);
int myfunc(int a)
{
int sum=0;
_asm
{
mov dword ptr [a],0Ch
mov eax,dword ptr [sum]
add eax,dword ptr [a]
mov dword ptr [sum],eax
mov ecx,dword ptr [a]
add ecx,1
mov dword ptr [a],ecx
}
printf("%d",a);
return 0;
}
int testCaller(int(*funcptr) (int a))
{
_asm
{
push 10h
call dword ptr [funcptr]
add esp,4
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
testCaller(myfunc);
return 0;
}
Give the output of the following code snippet :
void main()
{
int a=30,c=20,b=20;
_asm
{
mov eax,20
mov ebx,dword ptr[b]
cmp eax,ebx
jle Label2
xor eax,ebx
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
jnz Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void first()
{
printf("Func1");
}
void second()
{
printf("Func2 ");
first();
}
void main()
{
void (*ptr)();
ptr = second;
ptr();
}
Give the output of the following code snippet :
void main()
{
int a=20,b=30,c=40;
unsigned int d=2;
int x=1,y=2,z=30;
x= c | b && a ;
y = x | 2 || b;
printf("%d %d %d",x,y,-2 >> 2);
}
Give the output of the following code snippet :
int main()
{
int a = 2000;
int b = 1000;
int c = a >> 3;
int d = b >> 2;
if(c == d)
printf("True");
else
printf("False");
}
Give the output of the following code snippet :
int main()
{
float x = 0.3;
int y=10;
if (x == 0.3)
printf("%d",sizeof(x)+sizeof(0.3));
else if (x == 0.3f)
printf("%d",sizeof(0.3)+sizeof(0.3f));
else
printf("%d",sizeof(x)+sizeof(0.3f));
}
Give the output of the following code snippet :
void main()
{
int a=20,c=50,b=30;
_asm
{
mov eax,20
mov ebx,a
sub eax,dword ptr[a]
jc Label2
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
jne Label1
or eax,30
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
typedef struct student
{
char *a;
} stud;
void main()
{
stud s;
s.a = "Hello";
printf("%s", s.a);
}
A pointer may be of the types :
< NIL>
Give the output of the following code snippet :
struct
{
char *name;
union
{
char *sval;
} u;
} symtab;
void main()
{
symtab.u.sval="HelloWorld";
printf("%s",symtab.u.sval);
}
Give the output of the following code snippet :
void convertToBinary(int val)
{
for (int c = 7; c >= 0; c--)
{
int k = val >> c;
if (k & 1)
printf("1");
else
printf("0");
}
}
int main()
{
convertToBinary(89);
}
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=func;
printf("%d",(*f)());
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax, a
mov ebx, b
sub eax, ebx
mov c, eax
}
printf("%d", 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 */
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 : Assume the contents of the file 'Test.txt' is "Hello World".
void main()
{
char x;
int count=0;
FILE *fp,*fp1;
fp=fopen("Test.txt","r");
fseek(fp,10,SEEK_SET);
fputc('S',fp);
fclose(fp);
fp1=fopen("Test.txt","r");
while((x=getc(fp1))!=EOF)
{
printf("%c",x);
count++;
}
printf(" %d",count);
fclose(fp1);
}
Give the output of the following code snippet :
void main()
{
int a=50,c=10,b=10;
_asm
{
mov eax,35
mov ebx,a
sub eax,dword ptr[b]
jae Label2
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
je Label1
sub 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 = 20;
int b = 20;
if ((a < < 1) == (b * 2))
printf("True ");
else
printf("False");
}
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 a=10, b=20, c;
c = (a == 100 && b > 30);
c= a++ + b++ + ++c;
printf("%d", c);
return 0;
}
Give the output of the following code snippet who's solution configuration has been set to the DEBUG mode :
int main()
{
int a = 20, b = 10, c = 2;
_asm
{
mov eax, esp
mov ebx, 100
push dword ptr[b]
mov ecx, esp
pop dword ptr[b]
mov ebx, dword ptr[b]
sub ecx, eax
mov a, ecx
mov b, ebx
pop edx
add esp,8
}
printf("%d %d", a, b);
}
What do the following lines of code indicate?
else
{
prev->next=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 :
void main()
{
char *s = "SourceLens";
char *p = &s;
printf("%c %c", *(p+1), s[10]);
}
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 */
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 :
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;
}
Give the output of the following code snippet :
int main()
{
int a = 20, b = 10,c=2;
_asm
{
mov eax,100
push eax
push ebx
mov ecx,esp
sub ebx,ecx
pop ebx
pop eax
mov a,eax
mov b,ebx
}
printf("%d %d",a,b);
}
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->next;
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 :
union
{
int x;
char y;
} p;
int main()
{
p.x = 10;
printf("%d\n", sizeof(p));
}
Give the output of the following code snippet :
int main()
{
int ary[4] = {1, 2, 3, 4};
int *p = ary + 3;
printf("%d\n", p[-1]);
}
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]));
while(!argc);
}
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.5,4.5,-1));
}
Give the output of the following code snippet :
void convertToBinary(int val)
{
for (int c = 7; c >= 0; c--)
{
int k = val >> c;
if (k & 1)
printf("1");
else
printf("0");
}
}
int main()
{
convertToBinary(66);
}
Give the output of the following code snippet :
union Test
{
char str[10];
};
int main()
{
union Test st1, st2;
strcpy(st1.str, "Hello");
st2 = st1;
printf("%s",st2.str);
}
Give the output of the following code snippet :
int main()
{
int i, *j, k;
_asm
{
mov dword ptr[i], 1Ah
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov edx, dword ptr[ecx]
sub edx, 5
mov eax, dword ptr[j]
mov dword ptr[eax], edx
mov ecx, dword ptr[j]
mov edx, dword ptr[i]
imul edx, dword ptr[ecx]
mov eax, dword ptr[j]
sub edx, dword ptr[eax]
mov dword ptr[k], edx
}
printf("%d\n", k);
}
Give the output of the following code snippet :
int main()
{
struct u
{
unsigned char x : 1;
unsigned int y : 2;
float z :3;
} p;
struct u un;
un.z = 1.25;
printf("%f\n", un.f);
}
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 :
union stud
{
int age;
char *name;
};
void main()
{
union stud s= {20};
union stud *temp=(stud*)malloc(sizeof(stud));
temp=&s;
printf("%d",temp->age);
}
Give the output of the following code snippet :
void main()
{
char str[10]="Hello";
char *str2;
str2="World";
strcpy(str,str2);
printf("%s ",str);
}
Which of the following is an example of a null pointer in C?
< NIL>
Give the output of the following code snippet :
void main()
{
int a = 10;
int b = 20;
int c = 30;
int d = 0;
__asm
{
mov eax,c
push eax
mov eax,b
push eax
mov eax,a
push eax
mov eax,Func
mov dword ptr[d],eax
call dword ptr[d]
mov ebx,End
jmp ebx
Func :
add esp,4
pop eax
mov a, eax
pop eax
mov b, eax
pop eax
mov c,eax
sub esp,0x10
ret
End : add esp, 0x10
}
printf("%d %d %d", a, b,c);
}
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 :
void main()
{
int a=20,c=10,b=10;
_asm
{
mov eax,40
mov ebx,dword ptr[c]
cmp eax,ebx
jnbe Label2
shr eax,2
and eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
je 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,b=30,c=40;
unsigned int d=2;
int x=1,y=2,z=30;
x= c || b & a ;
y = x || 2 || b;
printf("%d %d %d",x,y,-2 < < 2);
}
Give the output of the following code snippet :
int main()
{
int a = 10;
int b = 10;
if (a == (a|b) || a == (a&b))
printf("True ");
else
printf("False");
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 1;
_asm
{
Label1 : mov eax, dword ptr[a]
add eax, dword ptr[j]
mov dword ptr[a], eax
mov ecx, dword ptr[i]
add ecx, 1
mov dword ptr[i], ecx
mov edx, dword ptr[j]
sub edx, 1
mov dword ptr[j], edx
jne Label1 }
printf("%d", a);
}
Give the output of the following code snippet who's solution configuration has been set to the DEBUG mode :
int main()
{
int a = 0;
int b = 0;
int c = 0;
_asm
{
mov eax, 10
push eax
mov ebx, dword ptr[esp]
mov a, ebx
mov ebx, dword ptr[esp + 4]
mov b, ebx
push 300
mov ebx, dword ptr[esp + 8]
mov c, ebx
add esp,4
pop eax
}
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
void main()
{
int row=2,col=2;
int **arr;
int i,j;
arr=(int*)malloc(row*sizeof(int));
for(i=0; i< row; i++)
arr[i]=(int*)malloc(col*sizeof(int));
for(i=0; i< row; i++)
{
for(j=0; j< col; j++)
{
arr[i][j]=i+j*i;
printf("%d ",arr[i][j]);
}
}
}
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 */
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"
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
struct q
{
char *name;
};
struct q *ptrary[3];
int main()
{
struct q *p;
p->name = "Hello";
ptrary[0] = p;
p->name= "World";
ptrary[1] = p;
printf("%s\n", ptrary[0]->name);
return 0;
}
Give the output of the following code snippet :
void main()
{
char *s= "Hello";
char *p = s;
printf("%c %c", p[0], s[1]);
}
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);
}
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 :
int main()
{
int i, *j, k;
_asm
{
mov dword ptr[i], 0Fh
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov eax, dword ptr[i]
add eax, dword ptr[ecx]
mov ecx, dword ptr[j]
cdq
imul dword ptr[ecx]
sub eax, dword ptr[i]
mov dword ptr[k], eax
}
printf("%d\n", k);
return 0;
}
Give the output of the following code snippet :
void func(char *a,char *b)
{
while(*a=*b)
{
a++;
b++;
}
}
void main()
{
char str1[15]="Hello world";
char *str="Yellow World";
char *x,*y;
x=str1;
y=str;
func(x,y);
printf("%s",str1);
}
Give the output of the following code snippet :
void main()
{
int a=10,c=20,b=-30;
_asm
{
mov eax,40
mov ebx,dword ptr[b]
cmp eax,ebx
jle Label2
or eax,ebx
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
jz Label1
or eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
union p
{
int x;
char y;
};
int main()
{
union p p1[] = {1, 92, 3, 94, 5, 96};
union p *ptr1 = p1;
int x = (sizeof(p1) / 6);
if (x == sizeof(int))
printf("%d\n", ptr1->x);
else
printf("False");
}
Give the output of the following code snippet :
int main()
{
int a = 0;
int b = 0;
int c = 0;
_asm
{
mov eax, 10
push eax
mov ebx, 100
push ebx
mov ecx, 1000
push ecx
push 100
mov ebx, dword ptr[esp]
mov a, ebx
mov ebx, dword ptr[esp+4]
mov b, ebx
mov ebx, dword ptr[esp-8]
mov c, ebx
add esp, 0x10
}
printf( "%d %d %d", a, b, c );
}
Give the output of the following code snippet :
struct student
{
char *name;
int age;
};
struct student s[2];
void main()
{
s[0].name = "Jenn ";
s[1] = s[0];
printf("%d %d", s[0].age, s[1].age);
}
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 :
void main()
{
int a=100,c=0,b=0;
_asm
{
mov eax,-15
mov ebx,a
sub eax,ebx
mov b,eax
add eax,a
jns Label1
mov c,ebx
}
Label1: printf("%d %d",b,c);
}
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 */
static int value;
void func();
void func1();
/* Test1.c */
#include "Test1.h"
int value = 100;
void func()
{
value=200;
printf ( "Output = %d\n", ++value );
func1();
}
/* Test2.c */
#include "Test1.h"
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p, q;
p.name = "SourceLens";
p.next = NULL;
ptrary[0] = &p;
strcpy(q.name, p.name);
ptrary[1] = &q;
printf("%s\n", ptrary[0]->name);
return 0;
}
Give the output of the following code snippet :
void func(int arr[2][5])
{
**arr++;
printf("%d ",**arr);
}
int main()
{
int arry[2][5]= {1,2,3,4,5,6};
func(arry);
printf("%d ",**arry+3);
}
Give the output of the following code snippet :
void main()
{
int a=20,c=-10,b=30;
_asm
{
mov eax,10
mov ebx,b
cmp eax,dword ptr[b]
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 : 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);
}
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 */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
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!=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()
{
int a=10,b=20,c=30;
unsigned int d=12;
int x,y,z;
x=a && b && c;
y=x< < 2;
z=y>>2;
printf("%d %d %d",x,y,~z);
}
Give the output of the following code snippet :
int main()
{
char *str = "Hello";
char *ptr = "World";
str = ptr;
printf("%s %s\n", str, ptr);
}
Give the output of the following code snippet :
int main()
{
int *Pa1, *Pa2, *Pa3;
int a1, b1,c;
_asm
{
mov dword ptr[a1], 0Ah
mov dword ptr[b1], 0Ch
lea eax, [a1]
mov dword ptr[Pa1], eax
lea ecx, [b1]
mov dword ptr[Pa2], ecx
mov edx, dword ptr[Pa1]
mov eax, dword ptr[Pa2]
mov ecx, dword ptr[edx]
imul ecx, dword ptr[eax]
mov dword ptr[c], ecx
lea edx, [c]
mov dword ptr[Pa3], edx
}
printf("%d", *Pa3);
}
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,10
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 :
union u
{
union
{
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 :
void main()
{
char *s= "Hello";
char *p = s;
printf("%c %c", *(p + 3), s[1]);
}
Give the output of the following code snippet :
int main()
{
int a=10, b=20,*ptr,*qtr;
ptr=&a;
qtr=&b;
*ptr=b++;
*qtr=*ptr+a;
printf("%d %d %d", a,*ptr,*qtr);
return 0;
}
Give the output of the following code snippet :
int main()
{
int a,b=2,c=10;
_asm
{
mov dword ptr[a],0
mov dword ptr[b],20
add eax,dword ptr[c]
or ebx,eax
shr dword ptr[a]
inc ebx
mov a,ebx
}
printf("%d",a);
}
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 *f()
{
int*p;
int x=100;
p=&x;
return p;
}
void main()
{
void *ptr;
ptr=f();
printf("%d",*(int*)ptr);
}
Give the output of the following code snippet :
void main()
{
int (*arr)[3];
int arry[5]= {1,2,3};
arr=&arry;
printf("%d",*(*arr));
}
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","Hello","World");
fclose(fp);
}
Give the output of the following code snippet :
struct p
{
int x;
char y;
struct p *ptr;
};
int main()
{
struct p t = {1, 2, &t};
printf("%d\n", t.ptr.y);
return 0;
}
Give the output of the following code snippet :
char *func()
{
char str[20];
strcpy(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()
{
int i, sum = 0;
_asm
{
mov dword ptr[i], 0
jmp Label1
Label3 : mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
Label1 : cmp dword ptr[i], 3
jge Label2
mov ecx, dword ptr[i]
imul ecx, dword ptr[i]
add ecx, dword ptr[sum]
mov dword ptr[sum], ecx
jmp Label3
}
Label2: printf("%d", sum);
}
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)));
printf("%d",sizeof(*arr));
}
Give the output of the following code snippet run with the following commandline arguments:
>Testfile.c 1 2
/* Testfile.c */
int main(int argc, char *argv[])
{
printf("%d %s", argc, argv[1]);
return 0;
}
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
push 70
push 80
call label1
add eax,ebx
mov a,eax
mov b,ebx
add esp, 20
jmp Label2
label1:
mov eax, dword ptr[esp + 8]
mov a, eax
add a, ebx
mov eax, dword ptr[esp + 12]
mov b, eax
mov eax, dword ptr[esp + 20]
or edx,ecx
mov c,eax
add edx,ecx
sub edx,10
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 = ary + 2;
printf("%d\n", p[-1]);
}
Give the output of the following code snippet :
struct student
{
int no;
char name[20];
};
int main()
{
struct student s;
s.no = 8;
printf("Hello");
}
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]
add eax, 26h
mov dword ptr[a], eax
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 40h
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 a,b,c=20;
_asm
{
mov dword ptr[a],15
mov dword ptr[b],10
and eax,ebx
xor eax,dword ptr[c]
mov a,eax
}
printf("%d",a);
}
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,1));
}
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("%d",st2->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 = 300;
/* Test1.c */
extern int value;
void func()
{
int value = 200;
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 :
void func(int *p)
{
printf("%d\n", *p);
}
int main()
{
int i = 10, *p = &i;
func(p++);
}
Give the output of the following code snippet :
int sum(int x, int y)
{
_asm
{
mov eax,dword ptr [x]
add eax,dword ptr [y]
}
}
void main()
{
int(*fptr)(int a, int b);
int a = 0;
fptr=sum;
_asm
{
push 14h
push 0Ah
call dword ptr [fptr]
add esp,8
mov dword ptr [a],eax
}
printf("%d", a);
}
Give the output of the following code snippet :
void main()
{
char arry[10]="Hello";
char str[15]="World";
const char* ptr=str;
*str='Y';
printf("%s",str);
}
Give the output of the following code snippet :
union student
{
int rollno;
char *name;
};
int main()
{
union student stud, studt;
stud.name = "Jenn";
studt.rollno = 101;
printf("%s\n", studt.name);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax,a
mov c,b
div ebx
mov dword ptr[a],ebx
mov dword ptr[b],eax
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
int main()
{
int i, *p, q;
_asm
{
mov dword ptr[i], 0Ah
lea eax, [i]
mov dword ptr[p], eax
mov ecx, dword ptr[p]
mov edx, dword ptr[ecx]
add eax,edx
mov eax, dword ptr[p]
mov dword ptr[eax], edx
mov ecx, dword ptr[p]
mov edx, dword ptr[ecx]
add edx, dword ptr[i]
mov dword ptr[q], edx
mov eax, dword ptr[p]
add eax, 10
mov dword ptr[p], eax
}
printf("%d", q);
}
Give the output of the following code snippet :
struct p
{
char *name;
struct p *next;
};
struct p *ptrary;
int main()
{
struct p p, q;
p.name = "SourceLens";
p.next=NULL;
ptrary= &p;
strcpy(q.name, p.name);
ptrary = &q;
printf("%s\n", ptrary->next);
return 0;
}
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);
}
Give the output of the following code snippet :
int main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
_asm
{
mov eax, 10
push eax
push 100
push 200
push 300
push 400
mov ebx, dword ptr[esp]
mov a, ebx
mov ebx, dword ptr[esp+4]
mov b, ebx
mov ebx, dword ptr[esp+8]
mov c, ebx
mov ebx, dword ptr[esp+12]
mov d, ebx
add esp, 0x10
}
printf( "%d",b);
}
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
shl eax,3
shl ebx,2
xor eax,ebx
mov dword ptr[a],ebx
mov dword ptr[b],eax
}
printf("%d %d",a,b);
}
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 :
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 :
void func(int arr[])
{
*arr++;
printf("%d ",(arr[0]));
}
int main()
{
int arry[10]= {1,2,3,4,5,6};
func(arry);
}
Give the output of the following code snippet :
struct emp
{
char name[20];
int age;
};
void func(struct emp*);
int main()
{
struct emp e = {"Jenn", 20};
func(&e);
printf("%s %d", e.name, e.age);
}
void func(struct emp *p)
{
p ->age=p->age+2;
}
Give the output of the following code snippet :
int main()
{
int x=100,y=200;
int z=++x || y--;
if(z < x%y || y%x)
printf("%d",z++- ++x);
else
printf("%d",z--+ --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 */
int value=300;
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
extern int value;
void main ()
{
printf ( "Output = %d", value );
}
Give the output of the following code snippet :
struct stud
{
int age;
char *name;
};
const struct stud s;
void main()
{
struct stud s2= {20,"Jenn"};
s=s2;
printf("%d",s.age);
}
Give the output of the following code snippet :
int main()
{
float arr[2][2]= {20.75,10.5,5.25,0.0};
int s=sizeof(arr);
int s1=sizeof(arr[1][1]);
int s3=sizeof(arr[0]);
printf("%d",s+s1/s3);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
__asm
{
push 100
push 200
call Func
jmp End
Func :
pop dword ptr[esp+4]
mov eax, dword ptr[esp+4]
mov a, eax
pop dword ptr[esp+8]
mov eax, dword ptr[esp + 8]
mov a, eax
ret
End :
}
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
void main()
{
char *str;
char *str2;
str="Hello";
str2="World";
str=str2;
printf("%s",str);
}
If pointers p and q point to members of the same array, then which of the following relations are legal?
< NIL>
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 func(float);
void (*fptr)(float) = func;
int main()
{
fptr(100);
}
void func(float i)
{
printf("%d ", i);
}
Consider a singly linked list with the elements 10,20,30,40 in that order. Predict the output of the following code :
typedef struct Node
{
int data;
struct Node *next;
} node;
void print(node *pointer)
{
printf("%d ",pointer->data);
print(pointer->next);
}
void main()
{
node *start,*temp;
start = (node *)malloc(sizeof(node));
temp = start;
temp -> next = NULL;
print(start->next);
}
Give the output of the following code snippet :
void main()
{
int a=50,c=10,b=10;
_asm
{
mov eax,10
mov ebx,a
sub eax,dword ptr[c]
jnb Label2
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
je Label1
add eax,dword ptr[b]
mov c,eax
}
Label1: printf("%d %d",b,c);
}
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 main()
{
int ch=0,sum=0,i;
int num=300,n=10,temp;
temp=num;
while(temp!=0)
{
temp>>=2;
ch++;
}
printf("%d",ch);
}
Which of the following operators is used to access the address of an object?
< NIL>
Give the output of the following code snippet :
void main()
{
char *str1="%s";
char str[]="Hello World";
printf(str1,str+1);
}