Knowledge check.
- Choose one best answer from given 4 choices for each questions.
- Review before submitting, as you won't get a chance to review after submitting.
- 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 :
void main()
{
int a = 100;
_asm
{
jmp Label1
jmp Label1
mov dword ptr[a], 64h
Label1: mov dword ptr[a], 0C8h
}
printf("%d", a);
}
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 :
void main()
{
char str1[15]="Hello World";
char str[10]="Yellow";
char str2[10]="\0World";
strcat(str,str2);
printf("%d %c",strlen(str),"HelloWorld"[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 */
extern int value;
extern int arg;
void func(int);
/* Test1.c */
#include "Test1.h"
void func(int arg)
{
value=200;
printf ( "Output = %d\n", arg+value );
}
/* Test2.c */
#include "Test1.h"
int value = 200;
void main ()
{
value = 300;
func(arg+value);
}
What are pointers?
< NIL>
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 :
void func(struct stud *stuobj);
struct stud
{
char *name;
int no2;
};
void main()
{
struct stud s;
s.name="Jenn";
func(&s);
}
void func(struct stud *stuobj)
{
struct stud *s;
s=stuobj;
printf("%s",s->name);
}
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
add esp,8
}
printf("%d %d", a, b);
}
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 = y>> 2;
printf("%d %d %d",x,y,z);
}
Give the output of the following code snippet :
struct stud
{
int age;
char *name;
};
void func(struct stud *ob)
{
struct stud *pobj;
pobj=ob;
pobj->age=22;
printf("%d",pobj->age);
}
void main()
{
const struct stud s2= {20,"Jenn"};
func(&s2);
}
Give the output of the following code snippet :
int mult(int x, int y)
{
_asm
{
mov eax,dword ptr [x]
mul dword ptr [y]
}
}
void main()
{
int(*fptr)(int a, int b);
int a = 0;
fptr=mult;
_asm
{
push 64h
push 4h
call dword ptr [fptr]
add esp,8
mov dword ptr [a],eax
}
printf("%d", a);
}
Give the output of the following code snippet :
typedef int INT;
typedef float FLOAT;
void main()
{
FLOAT a=100,b=200;
INT x=10,y=20;
float c=10;
c=a+b-x/y;
printf("%.2f %.2f",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;
printf("%d ",arr[i][j]);
}
}
free(arr);
printf("%d",sizeof(arr));
}
Consider the given lines of code : What does the line below signify?
temp->next=temp2;
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 :
void main()
{
int a=10,c=50,b=30;
_asm
{
mov eax,5
mov ebx,a
sub eax,dword ptr[a]
jc Label2
xor eax,dword ptr[c]
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
je Label1
or eax,b
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int f(int i)
{
int sum=0;
_asm
{
mov dword ptr [sum],0C8h
imul eax,dword ptr [i],0Ah
mov dword ptr [i],eax
mov ecx,dword ptr [sum]
add ecx,dword ptr [i]
mov dword ptr [sum],ecx
mov eax,dword ptr [sum]
}
}
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 :
void main()
{
unsigned int a=10;
unsigned int b=17;
int c = a ^ 2;
int d = ~b;
printf("%d %d",c,d);
}
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);
}
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 :
void func(char **a)
{
printf("%s",*(a+5));
}
void main()
{
char *str[15]= {"This","is","a","Hello","World","Program"};
char *x;
x=str[4];
str[4]=str[5];
str[5]=x;
func(str);
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=0;
_asm
{
mov eax,10
mov ebx,a
and eax,dword ptr[c]
jz Label2
mov b,eax
Label2:
mov ecx,c
cmp eax,ecx
jns Label1
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
struct p
{
int x;
int y;
};
int main()
{
struct p p1[];
struct p *ptr1 = p1;
int x = (sizeof(p1) / sizeof(ptr1));
if (x == 2)
printf("%d\n", ptr1->x);
else
printf("%d",x);
}
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", p1[4].x);
else
printf("%d\n", p1[0].y);
}
Give the output of the following code snippet :
void main()
{
int a = 5;
_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
jmp Label3
Label1 : mov eax, dword ptr[a]
add eax, 5
mov dword ptr[a], eax
jmp Label3
Label2 : mov eax, dword ptr[a]
add eax, 0Ah
mov dword ptr[a], eax
}
Label3: printf("%d", a);
}
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 :
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 :
union student
{
int no;
float no1;
double no2;
};
void main()
{
union student s= {10,20.5,30.5};
printf("%d",s.no);
}
Give the output of the following code snippet :
struct outer
{
int num;
struct inner
{
char num2;
} u;
} symtab;
void main()
{
symtab.u.num2=100;
printf("%d",symtab.u.num2);
}
Give the output of the following code snippet :
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
printf("%d", sizeof(s));
}
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 :
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 :
union stud
{
int age;
char *name;
};
void main()
{
union stud s;
union stud *temp=(stud*)malloc(sizeof(stud));
temp->name="Jenn";
temp->age=22;
printf("%s",temp->name);
}
Give the output of the following code snippet :
typedef union ut
{
int Ival;
float fval;
char s[20];
};
void main()
{
ut u, *pu, au[5];
printf("%d",sizeof(au));
}
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 :
union p
{
int x;
char y;
};
int main()
{
union p p1[] = {1, 92, 3};
union p *ptr1 = p1;
int x = (sizeof(p1));
printf("%d\n", 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 :
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 :
void main()
{
int a=30,c=-10,b=30;
_asm
{
mov eax,10
mov ebx,b
sub eax,dword ptr[a]
jo Label2
mov edx,dword ptr[c]
xor 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);
}
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 :
union temp
{
int a;
float b;
char c;
};
void main()
{
union temp t;
printf("%d",sizeof(t));
}
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 = 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 :
void fun(int *ptr)
{
*ptr = 30;
}
int main()
{
int y = 20;
fun(&y);
printf("%d", y);
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[0].u.sval);
}
Consider the given structure and state whether it is a self referencing structure :
struct node
{
int x;
struct node *next;
}*Head;
The & operator cannot be used to applied to which of the following?
< NIL>
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;
y=a | b;
z=x | y & c;
printf("%d %d %d",x,y,z);
}
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
jnc Label2
or eax,c
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
jne Label1
and eax,50
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;
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 );
}
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()
{
int i, *j, k;
_asm
{
mov dword ptr[i], 0Ah
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov eax, dword ptr[i]
imul eax, dword ptr[ecx]
mov ecx, dword ptr[j]
cdq
idiv dword ptr[ecx]
add eax, dword ptr[i]a
mov dword ptr[k], eax
}
printf("%d\n", k);
return 0;
}
Give the output of the following code snippet :
int main()
{
int ary[2][3];
int j = 20;
*ary[0] = j;
printf("%d %d", *ary[0],sizeof(ary));
}
Give the output of the following code snippet :
typedef struct test
{
int id;
} Test;
int main()
{
Test t1;
t1.id=10;
printf("%d",t1.id);
}
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);
}
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"
void func1()
{
printf ( "Output = %d\n", ++value );
func();
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
int value = 200;
void main ()
{
func();
}
Give the output of the following code snippet :
typedef int(*fptr)(int a);
typedef struct
{
int a;
fptr fpt[100];
} fp;
int fun(int a)
{
_asm
{
mov dword ptr[a], 0C8h
mov eax,3Ah
add dword ptr[a],eax
}
printf("%d", a);
return 0;
}
int _tmain()
{
fp myS;
myS.fpt[0] = fun;
_asm
{
push 64h
mov edx, 4
imul eax, edx, 0
mov ecx, dword ptr[ebp + eax - 190h]
call ecx
add esp, 4
}
}
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 :
int main()
{
struct Temp
{
char one:1;
};
struct Temp var = {1};
printf("%c\n", var.one);
return 0;
}
Give the output of the following code snippet :
int main()
{
int *a[3];
a = (int*) malloc(sizeof(int)*3);
printf("%d",sizeof(*a));
free(a);
return 0;
}
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()
{
printf("Output = %d",value);
}
/* Test2.c */
int value = 200;
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func();
func();
}
Give the output of the following code snippet :
struct p1
{
unsigned int x : 4;
unsigned int y : 2;
};
int main()
{
struct p1 p;
p.x = 11;
p.y = 2;
printf("%d\n", p.x);
}
Which of the following statements is true about an array of void data type?
< NIL>
Give the output of the following code snippet : Assume address of p is 5000
int main()
{
int *p;
printf("%p ",p);
p=p+1;
printf("%p",p);
}
Consider the following snippet: Where is the node temp2 added?
void add( 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;
}
Give the importance of the following lines of code from the given function :
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
temp->prev=NULL;
head=temp;
}
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;
}
}
Give the output of the following code snippet :
int f(int i)
{
int sum=0;
_asm
{
mov dword ptr [sum],14h
imul eax,dword ptr [i],3
mov dword ptr [i],eax
mov ecx,dword ptr [i]
imul ecx,dword ptr [i]
add ecx,dword ptr [sum]
mov dword ptr [sum],ecx
mov eax,dword ptr [sum]
}
}
void main()
{
int a;
int(*fptr)(int) = f;
_asm
{
push 5h
call dword ptr [fptr]
add esp,4
mov dword ptr [a],eax
}
printf("%d", a);
}
Give the output of the following code snippet :
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
s->c = "SourceLens";
printf("%s", s[0].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 i = 0, a = 105;
_asm
{
mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
Label2 : cmp dword ptr[i], 0
je Label1
mov ecx, dword ptr[a]
add ecx, 1
mov dword ptr[a], ecx
mov edx, dword ptr[i]
sub edx, 1
mov dword ptr[i], edx
jmp Label2
}
Label1: printf("%d", a);
}
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 :
int main()
{
enum state {working, failed};
enum result {failed, passed};
printf("%d",failed);
}
Consider the given code : Which of the following statements in the code is used to indicate that it is a self referencing structure?
struct node
{
int x;
struct node *next;
}
node *Head;
Give the output of the following code snippet :
union Test
{
char str[10];
char str2[20];
};
int main()
{
union Test st1, *st2;
strcpy(st1.str2,"Hello");
st2 = &st1;
printf("%s",st2->str);
}
Give the output of the following code snippet :
void main()
{
const char *str1;
char str2[]="Hello World";
str1=str2;
printf("%s",++str1);
}
Give the output of the following code snippet :
void main()
{
int a[2][5] = {1, 2, 3, 0};
for (int i = 0; i < 1; i++)
for (int j = 0; j < 1; j++)
printf("%d ", *a[0]);
}
Give the output of the following code snippet :
int main()
{
int a=10, b=20, c;
c = (a == 100 && b >= 10);
c= a-- + b++ + --c;
printf("%d", --c);
return 0;
}
Give the output of the following code snippet :
int main()
{
int a = 20;
int b = 20;
if ((a >> 1) == (a / 2))
printf("True ");
else
printf("False");
}
Give the output of the following code snippet :
void main()
{
int a=10,b=20,c=30;
unsigned int d=2;
int x=10,y=20,z=30;
x=a | b >> c || d;
y = a ^ 2 & b;
z = d >> 2;
printf("%d %d %d",x,y,z);
}
Give the output of the following code snippet :
struct temp
{
int a;
int b;
int c;
} p[] = {10,20,30,10};
void main()
{
printf("%d", sizeof(p));
}
Give the output of the following code snippet :
int f(int i)
{
int sum=0;
_asm
{
mov dword ptr [sum],14h
mov eax,dword ptr [i]
add eax,0Ah
mov dword ptr [i],eax
mov ecx,dword ptr [sum]
imul ecx,dword ptr [i]
mov dword ptr [sum],ecx
mov eax,dword ptr [sum]
}
}
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 _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
jmp Label2
label1:
add esp,4
mov eax, dword ptr[esp + 4]
mov a, eax
pop eax
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()
{
typedef int integer i = 10, *ptr;
integer j = i;
ptr = &j;
printf("%d\n", *ptr);
}
Give the output of the following code snippet :
struct temp
{
int a;
int b;
int c;
};
void main()
{
struct temp p[4] = {{1, 2, 3}, {4, 5, 6}, {7}};
printf("%d",sizeof(p));
}
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->prev;
}
printf("\n");
}
void display()
{
struct node *r;
r=head->next;
while(r->next!=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 main()
{
int a=20,c=20,b=30;
_asm
{
mov eax,30
mov ebx,dword ptr[b]
cmp eax,ebx
jnbe Label2
shl eax,1
or 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 main()
{
int *ptr1 = (int *)1000;
int *ptr2 = (int *)2000;
int var = ptr2 % ptr1;
printf("%d",var);
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 = 0;
int b = 0;
int c = 0;
int d = 0;
_asm
{
mov eax, 10
push eax
push 100
push 200
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
pop eax
add esp, 4
}
printf("%d %d", a, b);
}
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 emp *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 :
struct student
{
char c[10];
int age;
};
void main()
{
struct student s= {"Jenn",15};
struct student m;
m=s;
if(strcmp(m,s)==0)
printf("%s",m.c);
else
printf("%s",strupr(m.c));
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
void fun(struct point *p)
{
p->x=10;
printf("%d\n", p->x);
}
int main()
{
struct point p1 = {1, 2};
fun(&p1);
}
Give the output of the following code snippet :
void main()
{
int a=10,c=-10,b=30;
_asm
{
mov eax,10
mov ebx,b
cmp eax,dword ptr[b]
jnle Label2
mov edx,dword ptr[c]
or 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 :
#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 _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 f(int i)
{
_asm
{
mov eax,dword ptr [i]
add eax,64h
add eax,0Fh
mov ebx,2Ch
and 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 main()
{
char *a[1] = {"Hello"};
printf("%s", *a);
return 0;
}
Give the output of the following code snippet : Assume the array begins at the following address 5000
int main()
{
int arr[5]= {20,10,5,0,1};
int arry2[]= {*arr,*arr+2,*arr+3,*arr+4};
printf("%u %u",arr+1,&arr+1);
}
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 :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
__asm
{
push 100
push 200
push 300
call Func
jmp End
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, 0xC
}
printf("%d %d %d", a, b, c);
}
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 :
int main()
{
int c=10;
_asm
{
mov eax,10
mul dword ptr[c],20
mov c, eax
}
printf("%d", c);
}
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 :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 10, b = 10,c=0;
__asm
{
mov eax,Label1
call eax
mov ebx,Label2
jmp ebx
Label1 :
mov a, 50
ret
Label2 : mov b,100
}
printf("%d %d", a,b);
}
Give the output of the following code snippet :
int main()
{
int a[][] = {{1, 2, 3}, {5, 2, 3}};
printf("%d",*a[0]+1);
}
Give the output of the following code snippet :
int main()
{
int x=20,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 :
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 _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 ecx,Label2
jmp ecx
label1:
add esp,4
mov eax, dword ptr[esp + 4]
mov a, eax
mov eax, dword ptr[esp + 12]
mov b, eax
pop eax
mov c,eax
sub esp,8
ret
}
Label2:
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
void main()
{
char *a[10] = {"Yellow","Jello","Hello"};
printf("%d\n", sizeof(a));
}
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 :
void main()
{
int a=20,c=10,b=0;
_asm
{
mov eax,30
mov ebx,a
cmp eax,dword ptr[c]
je Label2
mov b,eax
Label2:
mov ecx,c
cmp eax,ecx
jns Label1
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=5;
_asm
{
mov ecx,0
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
add ecx,10
and ecx,ebx
xor ecx,ebx
mov dword ptr[c],ecx
}
printf("%d",c);
}
Give the output of the following code snippet :
void main()
{
char *str1="%s";
char str[]="Hello World";
printf(str1,str);
}
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;
/* Test2.h */
static int value;
void func(int);
/* Test1.c */
#include"Test2.h"
void func1(int);
void func(int arg)
{
value = 200;
func1(arg);
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"
int arg =20;
void main ()
{
func(arg);
}
Give the output of the following code snippet :
typedef void v;
v func(void*);
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()
{
char str[10]="Hello";
char *str2;
str2="World";
strcpy(str,str2);
printf("%s ",str);
}
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 :
#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 :
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 :
void main()
{
int i = 10,j = 2;
int ary[2][2];
*ary[1] = i;
printf("%d\n", *ary[1]);
}
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 :
void main()
{
int a = 10;
int b = 20;
int c = 20;
int d = 0;
__asm
{
push 100
push 200
mov eax,a
push eax
mov eax,Func
call eax
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, 0x8
}
printf("%d %d %d", a, b,c);
}
Give the output of the following code snippet :
int main()
{
enum days {Mon=3, Tue, Wed, Thu=-1, Fri, Sat=3,Sun};
printf("%d %d",Tue,Thu);
return 0;
}
In an array, a variable or expression of type array is the address of which element of the array?
< NIL>
Give the output of the following code snippet :
void main()
{
int a=40,c=20,b=20;
_asm
{
mov eax,20
mov ebx,dword ptr[a]
cmp eax,ebx
jng Label2
mov edx,b
xor edx,eax
and eax,edx
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp ecx,ebx
jne Label1
add eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
union p
{
unsigned int x : 2;
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 :
void main()
{
int a = 5;
_asm
{
mov eax, dword ptr[a]
mov dword ptr[ebp - 0D0h], eax
cmp dword ptr[ebp - 0D0h], 5
je Label1
cmp dword ptr[ebp - 0D0h], 6
je Label2
jmp Label3
Label1 : mov eax, dword ptr[a]
add eax, 5
mov dword ptr[a], eax
Label2 : mov eax, dword ptr[a]
add eax, 0Ah
mov dword ptr[a], eax
}
Label3: printf("%d", a);
}
Give the output of the following code snippet :
struct p
{
char *c;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p1;
printf("%d",sizeof(ptrary));
return 0;
}
Give the output of the following code snippet :
void main()
{
const int val=20;
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 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 main()
{
int a[10];
int b=sizeof(*a);
printf("%d",b);
}
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"
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 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);
}
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;
}
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);
printf("Output = %d\n",arg+value);
}
/* Test2.c */
#include"Test2.h"
void func1(int arg)
{
printf ( "Output = %d\n", arg+value );
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
int value = 300;
void main ()
{
func1(arg);
func(arg);
}
Give the output of the following code snippet :
int main()
{
int ***r, **q, *p, i=10;
p = &i;
q = &p;
r = &q;
printf("%d %d %d", *p, **q, ***r);
return 0;
}
Give the output of the following code snippet :
char *func()
{
char *str=(char *)malloc(20);
strcpy(str,"Hello World");
return str;
}
void main()
{
char *s;
s=func();
printf("%s",s);
}
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
mov ebx,35
mov eax, 45
call label1
add eax,ebx
mov a,eax
mov ecx,25
add ecx,eax
mov c,ecx
add esp, 12
jmp Label2
label1:
mov eax, dword ptr[esp + 4]
mov a, eax
add a, ebx
mov eax, dword ptr[esp + 8]
mov b, eax
or b,ebx
mov eax, dword ptr[esp + 12]
xor edx,ecx
mov c,eax
and edx,ecx
mov d,ebx
ret
}
Label2:
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
void main()
{
int (*arr)[3];
int arry[3]= {1,2,3};
arr=&arry;
printf("%d",*(*arr)+1);
}
Give the output of the following code snippet :
typedef struct
{
int a;
} Temp;
void main()
{
Temp t1;
t1.a=100;
printf("%d",t1.a);
}
Consider the following snippet : Where is the node 'temp' inserted?
void addtoLoc( int n,int num )
{
struct node *temp2,*temp;
temp2=head;
if(temp2==NULL)
{
printf("Empty List");
return;
}
for(int i=1; i< =n; i++)
temp2=temp2->next;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=temp2->next;
temp2->next=temp;
}
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= --z || ++y && x--;
int c= ++x % --y;
int b=(20,30)+a+(10,20,30)+c;
printf("%d %d",b,c);
}
Give the output of the following code snippet :
int main()
{
int i, *p, q;
_asm
{
mov dword ptr[i], 1Dh
lea eax, [i]
mov dword ptr[p], eax
mov ecx, dword ptr[p]
mov edx, dword ptr[ecx]
add edx, 15
mov eax, dword ptr[p]
mov dword ptr[eax], edx
mov ecx, dword ptr[p]
mov edx, dword ptr[ecx]
mov dword ptr[q], edx
mov eax, dword ptr[p]
sub eax, 10
mov dword ptr[p], eax
}
printf("%d", q);
}
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);
Display();
AddNode(20);
ReverseList();
Display();
}
Give the output of the following code snippet :
int f(int i)
{
_asm
{
mov eax,dword ptr [i]
add eax,64h
add eax,0Fh
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 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 func(char *s)
{
char *ptr;
ptr=s;
printf("%s",ptr);
}
void main()
{
char *str;
func(str);
}
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);
i=va_arg(marker,int);
printf("%d",i);
va_end(marker);
}
int main()
{
print(2,-1);
}
Give the output of the following code snippet :
void main()
{
int a=10,c=-10,b=50;
_asm
{
mov eax,30
mov ebx,b
sub eax,dword ptr[b]
jnle Label2
mov edx,dword ptr[c]
or edx,eax
mov b,edx
Label2:
mov ecx,dword ptr[a]
mov ebx,10
cmp ecx,ebx
jne Label1
add eax,ecx
or eax,edx
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 = 300;
void func();
/* Test1.c */
extern int value;
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
int value = 100;
void main ()
{
printf ( "Output = %d\n", value );
func();
}
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 :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax,a
mov ebx,b
add eax,ebx
div ebx
add eax,ebx
mov a,eax
mov b,ebx
}
printf("%d",a);
}
Give the output of the following code snippet :
void print(int num,...)
{
int i,j,k;
va_list marker;
va_start(marker,num);
j=va_arg(marker,char);
printf("%c ",j);
va_end(marker);
}
void print2(int num,...)
{
int i,j,k;
va_list marker;
va_start(marker,num);
j=va_arg(marker,int);
printf("%d ",j);
va_end(marker);
}
int main(int argc, char *argv[])
{
print('X','Y');
print2(88,89);
}
Give the output of the following code snippet :
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", strlen(a[1]));
}
Which is the only constant value that can be assigned to a pointer?
< NIL>
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 20, b = 30, c=0,d=0;
__asm
{
push 10
push 20
push 30
mov ebx,a
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
pop eax
mov a, eax
pop eax
mov b, eax
pop eax
mov c,eax
pop eax
mov d,eax
sub esp,20
ret
Label2:mov c,ebx
mov d,eax
}
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
int main()
{
char *a[] = {"p", "r", "o", "g", "r", "a", "m"};
printf("%s", *a);
}
Give the output of the following code snippet :
int main()
{
char *str = "Hello";
char strary[] = "Hello";
printf("%d %d\n", sizeof(str), sizeof(strary));
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 = 10;
int b = 20;
int c = 30;
_asm
{
mov eax, 10
push eax
push a
push b
push c
mov ebx, dword ptr[esp]
mov a, ebx
pop a
pop b
pop c
add esp,4
}
printf("%d %d %d", a, 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 */
extern int value;
static int arg;
void func(int);
/* Test1.c */
#include "Test1.h"
void func(int arg)
{
arg=10;
value=200;
printf ( "Output = %d\n", arg+value );
}
/* Test2.c */
#include "Test1.h"
void main ()
{
arg=20;
value = 300;
func(arg+value);
}
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 :
union stud
{
int age;
char *name;
};
void main()
{
union stud s= {20};
union stud *temp=(stud*)malloc(sizeof(stud));
temp=&s;
temp->age=30;
printf("%d",temp->age);
}
Give the output of the following code snippet :
union p
{
int x;
char y;
};
int main()
{
union p p1,*p2;
p1.x = 10;
p2=&p1;
printf("%d\n", p2->y);
}
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;
}
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 :
struct stud
{
int age;
char *name;
};
void func(const struct stud *ob)
{
struct stud *pobj;
pobj=ob;
pobj->age=22;
printf("%d",pobj->age);
}
void main()
{
struct stud s2= {20,"Jenn"};
func(&s2);
}
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)
r=r->next;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->prev;
}
}
void main()
{
func(100);
func(200);
func(300);
func(400);
display();
}
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);
}
Consider the following lines of code from the given program : What does temp2 store?
temp3=temp2;
temp2=temp1;
temp1=temp1->next;
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 :
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 :
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[1].Cobj.Id);
}
Give the output of the following code snippet :
void main()
{
enum days {MON=1,TUES,WED,THURS,FRI};
enum val;
for(int i=MON; i< FRI; i++)
{
printf("%d ",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->next;
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 :
int f(int i)
{
_asm
{
mov eax,dword ptr [i]
add eax,6Ah
add eax,0Fh
mov ebx,2Ch
and eax,ebx
xor eax,ebx
mov dword ptr [i],eax
mov eax,dword ptr [i]
}
}
void main()
{
int a;
int(*fptr)(int) = f;
_asm
{
push 0Fh
call dword ptr [fptr]
add esp,4
mov dword ptr [a],eax
}
printf("%d", a);
}
Give the output of the following code snippet :
void main()
{
int a[2][2] = {2,4,5,6,7,8};
for (int i = 0; i < 1; i++)
for (int j = 0; j < 1; j++)
printf("%d ", *a[1]+2);
}
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"
void func()
{
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 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);
}
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()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
extern int value = 100;
void main ()
{
func();
printf ( "Output = %d\n", value );
}
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);
}
Give the output of the following code snippet :
void main()
{
int a=30,c=20,b=10;
_asm
{
mov eax,20
mov ebx,c
sub eax,ebx
jna Label2
or eax,c
and eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
je Label1
or eax,50
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void func(char **a)
{
printf("%d",strlen(*a));
}
void main()
{
char *str1[15]= {"This","is","a","Hello","World","Program"};
char **x;
x=str1;
func(x);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 20, b = 30, c=0,d=0;
__asm
{
push 10
push 20
push 30
push 40
mov ebx,a
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
pop eax
mov a, eax
pop eax
mov b, eax
pop eax
mov c,eax
sub esp,16
ret
Label2:mov c,ebx
mov d,eax
}
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
int main()
{
const int x=200;
int y;
y=300;
int z=x+y;
printf("%d",z);
}
Give the output of the following code snippet :
void main()
{
int i, prod = 0, j = 5;
_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], 5
jge Label2
mov ecx, dword ptr[i]
add ecx, dword ptr[j]
imul ecx, dword ptr[prod]
mov dword ptr[prod], ecx
jmp Label3
}
Label2: printf("%d", prod);
}
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);
}
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 :
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 :
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","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 :
int main()
{
char ch = 'c';
char *chptr = &ch;
printf("%c",*chptr);
}
Give the output of the following code snippet :
void main()
{
int k=0,z;
printf("%d == 1" "%d " ,k,k==1?z=k++:z=--k);
}
Give the output of the following code snippet :
int main()
{
struct BitVal
{
int bit1:1;
int bit2:4;
} bit= {1,12};
printf("%d %d", bit.bit1, bit.bit2);
return 0;
}
Give the output of the following code snippet :
union Temp
{
int x;
char z;
};
void main()
{
union Temp t1[5];
printf("%d", sizeof(t1));
}
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 :
struct student
{
char a[10];
};
void main()
{
struct student s[] = {"Hello", "World"};
printf("%d", sizeof(s));
}
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]
mov ecx,dword ptr[c]
push eax
push ebx
sub eax,ecx
xor ebx,ecx
inc ebx
pop eax
mov a,eax
mov b,ebx
pop ebx
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
int main()
{
int c=0;
_asm
{
mov eax,100
add eax,dword ptr[c]
mov c, eax
}
printf("%d", c);
}
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 ebx,a
js Label1
mov c,ebx
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
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
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
int main()
{
struct u
{
unsigned char x : 1;
unsigned int y : 35;
} p;
struct u un;
un.y = 100;
printf("%d\n", un.y);
}
Give the output of the following code snippet:
void main()
{
char *s = "hello";
char *p = s[3];
printf("%c\t%c", *p, s[1]);
}
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 :
void main()
{
char str1[12]="Hello world";
char *str="Yellow World";
char *str2="%s";
printf(str2,&str+5);
}
Give the output of the following code snippet :
void func(int p[],int count)
{
for(int i=0; i< count; i++)
printf("%d ", *p);
}
int main()
{
int arry[5]= {1,2,3,4,5};
func(arry,5);
}
Give the output of the following code snippet :
void main()
{
int i, sum = 0, j = 5;
_asm
{
mov dword ptr[i], 0
jmp Label1
Label4 : mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
Label1 : cmp dword ptr[i], 5
jge Label2
mov ecx, dword ptr[i]
imul ecx, dword ptr[j]
add ecx, dword ptr[sum]
mov dword ptr[sum], ecx
cmp dword ptr[i], 3
jne Label3
jmp Label2
Label3 : jmp Label4
}
Label2: printf("%d", sum);
}
Give the output of the following code snippet :
int main()
{
double *ptr = (int *)100;
ptr = ptr + 2;
printf("%u", ptr);
}
Give the output of the following code snippet :
const int* func(int i)
{
int x=i;
int *ptr=&x;
return (ptr);
}
void main()
{
int a=10;
int *qtr=func(a);
printf("%d",*qtr);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
}*head;
void add( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
if (head== NULL)
{
head=temp;
head->next=NULL;
}
else
{
temp->next=head;
head=temp;
}
}
void display()
{
struct node *r;
r=head;
while(r!=NULL)
{
printf("%d ",r->data);
}
}
void main()
{
add(100);
add(200);
add(300);
add(400);
display();
}
Give the output of the following code snippet :
int main()
{
char str1[20] = "HelloWorld";
char str[10] = "World";
char *ret;
ret = strrev(str);
printf(" %s\n", ret);
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 */
void func();
/* Test1.c */
#include "Test1.h"
static int value=200;
void func()
{
printf ( "Output = %d\n", value );
}
/* Test2.c */
#include "Test1.h"
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet run with the following commandline arguments:
>Testfile.c one two
/* Testfile.c */
int main(int argc, char *argv[])
{
for(int i=1; i< argc; i++)
printf("%s ", argv[i]);
return 0;
}
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 */
int value = 100;
void func();
/* Test1.c */
#include "Test2.h"
int value = 100;
void func()
{
printf("Output = %d\n",value);
}
/* Test2.c */
#include "Test1.h"
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 :
struct stud
{
int age;
char *name;
};
void func(const struct stud *ob)
{
const struct stud *pobj;
pobj=ob;
printf("%d",pobj->age);
}
void main()
{
struct stud s2= {20,"Jenn"};
func(&s2);
}
Give the output of the following code snippet :
struct p
{
int x;
int y;
};
int main()
{
struct p p1[] = {1, 2, 3, 4, 5, 6};
struct p *ptr1 = p1;
printf("%d %d\n", ++ptr1->x, ++(ptr1 + 2)->x);
}
What do the following lines of code in the function indicate?
else
{
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
}
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 :
int Mult(int first,...)
{
int prod=1, count=0,i=first;
va_list marker;
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 :
int mod(int a, int b)
{
return a % b;
}
void main()
{
int (*fptr)( int,int)= &mod;
printf("%d",(*fptr)(10,6));
}
Give the output of the following code snippet :
void print(int num,...)
{
int i,j,k;
va_list marker;
va_start(marker,num);
j=va_arg(marker,char);
printf("%c ",j);
va_end(marker);
}
void print2(int num,...)
{
int i,j,k;
va_list marker;
va_start(marker,num);
j=va_arg(marker,int);
printf("%d ",j);
va_end(marker);
}
int main(int argc, char *argv[])
{
print(10,'X','Y');
print(10,88,89);
}
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[0] = 'G';
printf("%s", t.arr);
}
Give the output of the following code snippet :
void main()
{
struct temp
{
int a;
struct temp1
{
float d;
} p;
};
struct temp st = {1,1.8};
printf("%d %f",st.a,p.d);
getch();
}
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;
};
void main()
{
struct student *s;
s->c = "SourceLens";
printf("%s", s->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
mov ebx, 20
push ebx
push 200
push 100
mov ecx, 30
push ecx
mov edx, 40
push edx
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 %d %d %d", a, b, c, d );
}
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->next;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
printf("\n");
}
void main()
{
func(100);
func(200);
func(300);
func(400);
Delete(100);
Delete(300);
Delete(400);
func(500);
display();
}
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 ebx
Label1 :
mov a, 64
ret
Label2 : mov b,100
}
printf("%d %d", a,b);
}
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 :
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 :
struct p
{
};
struct p *ptrary[10];
int main()
{
struct p p1;
printf("%d",sizeof(ptrary));
return 0;
}
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 run with the following commandline arguments:
>Testfile.c one two
/* Testfile.c */
int main(int argc, char **argv)
{
int i;
for(i=0; i< argc; i++)
printf("%s ", argv[i]);
}
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 :
void main()
{
int a = 100;
_asm
{
jmp Label1
jmp Label1
mov eax, dword ptr[a]
add eax, 64h
mov dword ptr[a], eax
jmp Label2
jmp Label2
Label1 : mov dword ptr[a], 0C8h
}
Label2: printf("%d", a);
}
Give the output of the following code snippet :
void main()
{
int a=30,c=10,b=-40;
_asm
{
mov eax,-40
mov ebx,dword ptr[b]
cmp eax,ebx
jl Label2
and eax,10
or 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 :
void main()
{
char str1[15]="Hello world";
char *str="Yellow World";
int i=12;
char *x,*y;
x=str1;
y=str;
while(*x=*y)
{
x++;
y++;
}
printf("%s",str1);
}
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 :
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 :
int(*funcptr) (char a);
int myfunc(char a)
{
_asm
{
mov byte ptr [a],42h
mov al,byte ptr [a]
add al,0Ah
mov byte ptr [a],al
}
printf("%c",a);
return 0;
}
int testCaller(int(*funcptr) (char a))
{
_asm
{
push 74h
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 a = 1;
_asm
{
mov eax, dword ptr[a]
mov dword ptr[ebp - 0D0h], eax
cmp dword ptr[ebp - 0D0h], 0
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(*funcptr) (int a);
int myfunc(int a)
{
int sum=0;
a=200;
_asm
{
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 64h
call dword ptr [funcptr]
add esp,4
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
testCaller(myfunc);
return 0;
}
Give the importance of the following line of code in the given function?
r=r->prev;
void func()
{
struct node *r;
r=head;
while(r->flink!=NULL)
r=r->flink;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->blink;
}
}
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 :
int main()
{
int a = 20, b = 10,c=2;
_asm
{
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
mov dword ptr[c],10
shl ecx,2
and ecx,ebx
mov dword ptr[a],ecx
}
printf("%d",a);
}
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->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 :
struct Vehicle
{
int Id;
char *name;
struct Car
{
int Id;
char *name;
} Cobj;
};
void main()
{
struct Vehicle *Vobj;
Vobj->Cobj.Id=1001;
strcpy(Vobj->Cobj.name,"Nano");
printf("%s",Vobj->Cobj.name);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20,c=5;
_asm
{
mov ecx,25
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
sub ecx,10
dec dword ptr[c]
and ecx,dword ptr[c]
mov a,ecx
}
printf("%d",c);
}
Give the output of the following code snippet :
int f(int i)
{
_asm
{
mov eax,dword ptr [i]
add eax,0Ah
mov dword ptr [i],eax
mov eax,dword ptr [i]
}
}
void main()
{
int a;
int(*fptr)(int) = f;
_asm
{
push 64h
call dword ptr [fptr]
add esp,4
mov dword ptr [a],eax
}
printf("%d", a);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
void fun(struct point *p)
{
p.x=10;
printf("%d\n", p.x);
}
int main()
{
struct point p1 = {1, 2};
fun(&p1);
}
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 :
union p
{
int x;
char y;
};
int main()
{
union p p1[] = {1, 92, 3, 94, 5, 96};
union p *ptr1 = p1;
if (ptr1->x == p1[0].x)
printf("%d\n", p1[4].x);
else
printf("%d\n", p1[2].y);
}
Give the output of the following code snippet :
void main()
{
int x=10,y=20,z=0;
if(x+y>y-x && x-y< y+x)
{
x=100;
y=200;
z=x*y/x;
}
else
z=300;
printf("%d %d %d",x,y,z);
}
Give the output of the following code snippet :
int main()
{
int a,b=2,c=10;
_asm
{
mov dword ptr[a],0
mov ecx,dword ptr[b]
mov dword ptr[b],20
add ecx,dword ptr[c]
or ecx,dword ptr[b]
inc ecx
mov a,ecx
}
printf("%d",a);
}
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 x=100,y=200;
int z = x++ || y;
int a= --z || ++y || x--;
int b=a+(10,20,30,40);
printf("%d %d",b,a);
}
Give the output of the following code snippet :
void main()
{
int k=0,z;
k==1?z=k++:z=--k;
printf("%d == 1 " "%d " ,z);
}
Give the output of the following code snippet :
void (*f)()
{
int*p;
int x=88;
p=&x;
return p;
}
void main()
{
void *ptr;
ptr=f();
printf("%c",*(char*)ptr);
}
Give the output of the following code snippet :
void func3(int x);
int i=100;
void func(int i)
{
printf("%d ",i++);
}
void func2(int i)
{
printf("%d ",i++);
func3(i);
}
void func3(int i)
{
printf("%d ",i++);
}
void main()
{
int x=10;
func(x);
func2(x);
}
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);
}
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);
}