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 run with the following commandline arguments:
>Testfile.c one two
/* Testfile.c */
int main(int argc, char *argv[])
{
while(--argc>0)
printf("%s ", *++argv+1);
return 0;
}
Give the output of the following code snippet :
union date
{
unsigned int d;
unsigned int m;
unsigned int y;
};
int main()
{
union date dt[] = {12, 10, 2000};
printf("Date is %d/%d/%d", dt[0].d, dt[0].m, dt[0].y);
}
Give the output of the following code snippet :
int main()
{
int ary[4] = {1, 2, 3, 4};
int p[4];
*p = ary[0];
printf("%d\n", p[1]);
}
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);
}
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 */
static int value;
void func();
/* Test1.c */
#include "Test1.h"
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 :
typedef void v;
v func(int,int);
void main()
{
v val;
func(10,10);
}
v func(int x,int y)
{
printf("%d",x+y);
}
Give the output of the following code snippet :
void main()
{
int arry[10]= {1,2,3,4};
printf("%d",*(arry+10));
}
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 DecToBin(int num)
{
if (num == 0)
{
return 0;
}
else
{
return (num % 2) + 10 * DecToBin(num / 2);
}
}
int main()
{
printf("%d",DecToBin(200));
}
Give the output of the following code snippet :
struct student
{
int mark1;
char *name1;
};
void main()
{
struct student stud;
stud.mark1=100;
stud.name1="Jenn";
struct student *s=&stud;
printf("%s",s.name1);
}
Give the output of the following code snippet :
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p.name = "SourceLens";
p.next = NULL;
ptrary[0] = &p;
printf("%s\n", ptrary[0]->name);
return 0;
}
Give the output of the following code snippet :
int main()
{
int i, *p;
_asm
{
mov dword ptr[i], 0Ah
lea eax, [i]
mov dword ptr[p], eax
mov ecx, dword ptr[p]
mov edx, dword ptr[p]
mov eax, dword ptr[edx]
mov dword ptr[ecx], eax
mov ecx, dword ptr[p]
mov edx, dword ptr[ecx]
add edx, 1
mov eax, dword ptr[p]
mov dword ptr[eax], edx
}
printf("%d", *p);
}
Give the output of the following code snippet :
int main()
{
char ch = 'c';
char *chptr = &ch;
printf("%c",*chptr);
}
Give the output of the following code snippet :
int main()
{
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 :
void func(struct stud *stuobj);
struct stud
{
int no;
char name[3];
stud *link;
};
void main()
{
struct stud *ptr=(stud *)malloc(sizeof(20));
char nameval[]="Penny";
strcpy(ptr->name,nameval);
func(ptr);
}
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 c=10;
_asm
{
mov c,100
add c,100
mov c, eax
}
printf("%d", c);
}
Give the output of the following code snippet :
void main()
{
char *str1="%s";
char str[]="Hello World";
printf(str1,"Hello");
}
Give the output of the following code snippet :
void main()
{
int a=10,b=20,c=30;
unsigned int d=12;
int x,y,z=40;
x=a && b || c;
y=x< < 2;
z>>=2;
printf("%d %d %d",x,y,~z);
}
Give the output of the following code snippet :
int main()
{
struct u
{
unsigned int x[10] : 1;
unsigned int y : 2;
} p;
struct u un= {2,5};
printf("%d %d",un.x,un.y);
}
Give the output of the following code snippet :
struct temp
{
int a;
int b;
int c;
} p[] = {10,20,3};
void main()
{
printf("%d", sizeof(p));
}
Give the output of the following code snippet :
int main()
{
int a = 20, b = 10,c=2;
_asm
{
mov eax,esp
mov ebx,100
push ebx
mov ecx,esp
pop ebx
sub ecx,eax
mov a,ecx
mov b,ebx
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
void func(int *val)
{
*val+=10;
}
void main()
{
int arry[10]= {1,2,3,4,5};
func(&arry[0]);
char str[15]="Hello World";
arry[2]=10;
str[0]='Y';
printf("%d %s",arry[2]+arry[0],str);
}
Give the output of the following code snippet : Assume the contents of the file 'Test.txt' is
Hello World
void main()
{
char ch;
char str[10];
int count=0;
FILE *fp;
int i=0;
fp=fopen("Test.txt","r");
while((ch=getc(fp))!=EOF)
{
if(ch=='\n'|| ch==' ')
{
i++;
}
}
printf("%d",i);
fclose(fp);
}
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"
void main ()
{
func(arg);
}
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();
}
Consider the given code given below : What do the nodes temp1 and temp2 point to?
temp2=temp1->next;
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
Give the output of the following code snippet :
int main()
{
int i = 5, a = 10;
_asm
{
Label2: cmp dword ptr[i], 0
je Label1
mov eax, dword ptr[i]
sub eax, 1
mov dword ptr[i], eax
mov ecx, dword ptr[a]
add ecx, dword ptr[i]
mov dword ptr[a], ecx
jmp Label2
}
Label1:printf("%d", a);
}
Give the output of the following code snippet :
void main()
{
char a[10][6] = {"Hola","Hello","Jello"};
printf("%s", a+1);
}
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 :
struct
{
unsigned int val : 3;
} Val;
int main( )
{
Val.val = 4;
printf( "%d ", Val.val );
Val.val = 7;
printf( "%d ", Val.val );
Val.val = 8;
printf( "%d ", Val.val );
return 0;
}
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.y);
}
void func(struct point *p)
{
p->x = 10;
}
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 20
push 30
push 40
call Func
jmp End
Func :
add esp, 4
pop eax
mov a, eax
pop eax
mov b, eax
pop eax
mov c, eax
and eax,b
shl eax,2
mov d,eax
sub esp, 0x10
ret
End : add esp, 0xC
}
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
int sum(char* first,...)
{
int sum=0, count=0,i;
va_list marker;
va_start(marker,first);
while(i!=0)
{
i=va_arg(marker,int);
printf("%d ",i);
}
va_end(marker);
return sum;
}
int main(int argc, char *argv[])
{
sum("Test",2,4,6,-1);
}
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 */
extern int value;
void func1();
/* Test2.h */
void func()
/* Test1.c */
#include "Test1.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"
void main ()
{
func();
func();
}
Give the output of the following code snippet :
typedef void v;
v func(int,int);
void main()
{
v val=100;
int x=(int)val;
func(x,10);
}
v func(int x,int y)
{
printf("%d",x+y);
}
A pointer may be of the types :
< NIL>
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 :
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 :
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(11001101);
}
Give the output of the following code snippet :
void func(int (*p)[2],int row,int col)
{
for(int i=0; i< row; i++)
{
for(int j=0; j< col; j++)
{
printf("%d ", p[i][j]);
}
}
}
int main()
{
int arry[2][2]= {1,2,3,4};
func(arry,2,2);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c 100 200 300
void func(char *arry[])
{
for(int i=0; i< 4; i++)
printf("%s ", (arry[i]));
}
int main(int argc, char *argv[])
{
func(argv);
return 0;
}
Give the output of the following code snippet :
int main()
{
union u
{
unsigned int x : 1;
unsigned int y : 4;
} p;
union u *un=(u*)malloc(sizeof(u));
un->y = 2;
printf("%d\n",sizeof(un));
}
Give the output of the following code snippet :
void func(char *s)
{
printf("%s",s);;
}
void main()
{
char str[]="Hello World";
char *str1="Hello world";
str1="New Program";
func(str1);
}
Which of the following are valid pointer operations in C?
< 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 :
int main()
{
enum state {working, failed};
enum result {failed, passed};
printf("%d",failed);
}
Give the output of the following code snippet :
void main()
{
int k = 2.5;
int *p = &k;
int **m = &p;
**m = 12;
printf("%d\n", *p);
}
Give the output of the following code snippet :
void main()
{
int a=100;
int b=200;
char str[10];
int x;
itoa(100,str,16);
printf("%s ",str);
}
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 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);
Delete(100);
Delete(200);
display(n);
}
Files Test1.c, Test1.h, Test2.c and Test3.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
extern int value;
void func();
void func1();
/* Test1.c */
#include "Test1.h"
int value = 300;
void func()
{
value=200;
printf ( "Output = %d\n", ++value );
func1();
}
/* Test2.c */
#include "Test1.h"
int value;
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=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 :
void fun(int *p)
{
int j = 5;
p = &j;
printf("%d ", *p);
}
int main()
{
int i = 100, *p = &i;
fun(&i);
printf("%d ", *p);
}
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 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 :
void main()
{
int i = 0, a = 10;
_asm
{
Label2: cmp dword ptr[i], 1
jle Label1
mov eax, dword ptr[a]
add eax, 2
mov dword ptr[a], eax
Label1 : mov ecx, dword ptr[i]
add ecx, 1
mov dword ptr[i], ecx
cmp dword ptr[i], 3
jne Label2
}
printf("%d", a);
}
Give the output of the following code snippet : Assume the input given is "Hello".
void main()
{
int i=3;
int x;
while(i!=0)
{
scanf("%d",&x);
printf("%d ",x);
break;
ungetc(x,stdin);
i--;
}
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
void func();
/* Test1.c */
#include "Test1.h"
static int value;
void func()
{
printf ( "Output = %d\n", ++value );
}
/* Test2.c */
#include "Test1.h"
static int value;
void main ()
{
func();
printf ( "Output = %d\n", ++value );
}
Give the output of the following code snippet :
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;
x=~z;
printf("%d %d %d",x,y,sizeof(z));
}
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()
{
const char str1="";
char str2[]="Hello World";
str1=str2;
printf("%s",str1);
Give the output of the following code snippet :
struct student
{
int mark1;
int mark2;
};
void main()
{
struct student stud= {100,95};
int *s;
s=(int*)&stud;
printf("%d",*s);
}
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","a+");
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 :
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 :
int main()
{
int i, *p, q;
_asm
{
mov dword ptr[i], 1Fh
lea eax, [i]
mov dword ptr[p], eax
mov ecx, dword ptr[p]
mov edx, dword ptr[ecx]
sub edx, 0Fh
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, 6
mov dword ptr[p], eax
}
printf("%d", q);
}
Give the output of the following code snippet :
void main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
__asm
{
push 100
push 200
mov eax,Func
call eax
mov ebx,End
jmp ebx
Func :
add esp,4
pop eax
mov a, eax
pop eax
mov b, eax
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 :
void main()
{
int a=20,c=0,b=0;
_asm
{
mov eax,-30
mov ebx,a
sub eax,ebx
jns Label2
mov b,eax
Label2: or eax,-20
mov c,ebx
js Label1
}
Label1: printf("%d %d",b,c);
}
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,st.t1.c,st.t1.d);
getch();
}
Give the output of the following code snippet :
struct q
{
char *name;
};
struct q *ptrary[3];
int main()
{
struct q *p;
p->name = "World";
ptrary[0] = p;
p->name= "Hello";
ptrary[1] = p;
p->name = "Welcome";
ptrary[2] = p;
printf("%s\n",ptrary[3]->name);
return 0;
}
Give the output of the following code snippet :
int main()
{
int a[2][2] = {1, 2, 3, 4};
int *ptr;
ptr = &a[0][0];
printf("%d\n", *ptr);
}
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));
}
Give the output of the following code snippet :
char *func()
{
char *str=(char*)malloc(20*sizeof(char));
strcpy(str,"Hello World");
return str;
}
void main()
{
char *s;
s=func();
printf("%s",s);
}
Give the output of the following code snippet :
int func()
{
int z=100;
if(z)
return z++;
else
return --z;
}
int main()
{
const int x=func();
int y;
y=x;
int z=x+y;
printf("%d",z);
}
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 :
struct node
{
int data;
struct node *next;
struct node *prev;
}*head;
void func( int num )
{
struct node *temp,*temp2;
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
temp->prev=NULL;
head=temp;
}
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
temp2->prev=temp;
}
}
void Delete(int num)
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=head->next;
head->prev=NULL;
}
else
{
if(temp->next==NULL)
temp->prev->next=NULL;
else
{
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
}
}
free(temp);
return;
}
temp= temp->next;
}
}
void display()
{
struct node *r;
r=head;
while(r->next!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
printf("\n");
}
void main()
{
func(100);
func(200);
func(300);
func(400);
Delete(300);
Delete(400);
display();
}
Give the output of the following code snippet :
union point
{
int x;
int y;
};
int main()
{
union point p1= {1, 2};
union point *ptr1 = p1;
printf("%d %d",(ptr1)->x,ptr1->y);
}
Give the output of the following code snippet :
void main()
{
int a=10,c=20,b=30;
_asm
{
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
sub eax,ebx
jge Label2
shl eax,1
xor eax,b
mov b,eax
Label2:
mov ecx,a
sub ecx,ebx
jz Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int main()
{
int i, *p, q;
_asm
{
mov dword ptr[i], 2
lea eax, [i]
mov dword ptr[p], eax
mov ecx, dword ptr[p]
mov edx, dword ptr[ecx]
add edx, 0Ah
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]
add eax, 4
mov dword ptr[p], eax
}
printf("%d", q);
}
Give the output of the following code snippet :
void main()
{
char a[10][5] = {"Welcome","Hello","Jello"};
printf("%s", a[0]);
}
Give the output of the following code snippet :
int f()
{
int*p;
int x=100;
p=&x;
return *p;
}
void main()
{
int ptr;
ptr=f();
printf("%d",ptr);
}
Give the output of the following code snippet :
int main()
{
int *ptr1,*ptr2;
ptr1 = (int *)1000;
ptr2 = ptr1/4;
return(0);
}
Which of the following line of code is responsible for the actual reversal of the links in the particular program?
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 :
int main()
{
int arry[5]= {20,10,5,0};
arry[5]=10;
arry[6]=++(*arry);
printf("%d %d",3[arry],sizeof(arry));
}
Consider the following code: Where are the elements added to in the list?
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 main()
{
func(100);
func(200);
func(300);
func(400);
display();
}
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(m==s)
printf("%s",m.c);
else
printf("%s",strupr(m.c));
}
Give the output of the following code snippet :
int mod(int a, int b)
{
return a % b;
}
void main()
{
int (*fptr)(int, int);
fptr = &mod;
printf("%d",(*fptr)(10,6));
}
Give the output of the following code snippet :
void main()
{
int a=10,c=10,b=10;
_asm
{
mov eax,30
mov ebx,c
sub eax,ebx
jna Label2
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
jne Label1
and eax,50
mov c,eax
}
Label1: printf("%d %d",b,c);
}
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()
{
struct stud s2= {20,"Jenn"};
func(&s2);
}
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-y/x;
printf("%.2f %.2f",a+b,c);
}
Give the output of the following code snippet :
int func(int *x)
{
int *ptr;
int y=100;
ptr=x;
ptr=&y;
return *ptr;
}
void main()
{
int (*f[5])(int*);
int *a;
int b=200;
a=&b;
f[0]=func;
printf("%d",(*f)());
}
Give the output of the following code snippet :
void main()
{
int row=2,col=2;
int **arr;
int i,j;
arr=(int*)malloc(2*2*sizeof(int));
for(i=0; i< row; i++)
{
for(j=0; j< col; j++)
{
arr[i*col+j]=i*i;
printf("%d ",arr[i*col+j]);
}
}
}
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;
z= a ^ y & d;
printf("%d %d %d",x, y,z);
}
Give the output of the following code snippet :
char sub1()
{
return "HelloWorld";
}
void main()
{
char (*function_pointer)();
function_pointer = &sub1;
printf("%s",(*function_pointer)());
}
Give the output of the following code snippet :
void main()
{
int a=30,c=20,b=10;
_asm
{
mov eax,50
mov ebx,c
sub eax,ebx
jna Label2
xor eax,c
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
jne Label1
or eax,50
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 10, b = 10,c=10,d=10;
__asm
{
mov eax,Label1
mov dword ptr[c],eax
call eax
mov ebx,Label2
mov dword ptr[b],ebx
mov ecx,100
mov edx,25
jmp dword ptr[b]
Label1 :
mov a, 20
mov d, 30
ret
Label2 : mov b,edx
mov c,300
mov a,50
}
printf("%d %d %d %d", a,b,c,d);
}
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]
mov ecx,10
and ecx,ebx
inc 10
mov dword ptr[c],ecx
}
printf("%d",c);
}
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]
and ecx, dword ptr[a]
xor ecx,dword ptr[a]
mov dword ptr[sum], ecx
}
printf("%d", sum);
return 0;
}
int _tmain()
{
fp myS;
myS.fpt[1] = fun;
_asm
{
push 5Ah
mov ecx, 4
shl ecx, 0
mov edx, dword ptr[ebp + ecx - 28h]
call edx
add esp, 4
}
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=0;
_asm
{
mov eax,30
mov ebx,a
cmp eax,dword ptr[c]
jne 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 with the following command line arguments :
>Test.c Hello World
int main(int argc, char *argv[])
{
int i=0;
while(i!=argc)
{
printf("%s ", argv[i]);
i++;
}
return 0;
}
Give the output of the following code snippet :
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 b
mov ebx, dword ptr[esp+4]
mov b, ebx
pop c
add esp, 0x10
}
printf( "%d %d %d",a,b,c);
}
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 );
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
int value = 100;
void main ()
{
func1();
}
Give the output of the following code snippet :
int main()
{
int *p = (int *)12;
int *q = (int *)4;
printf("%d", p - q);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 10, b = 10,c=10,d=10;
__asm
{
mov eax,Label1
call eax
mov ebx,Label2
mov ecx,10
mov edx,25
cmp edx,ecx
jnz Label2
Label1 :
mov a, 20
mov d, 10
mov b,edx
ret
Label2 :
mov c,300
mov a,50
}
printf("%d %d %d %d", a,b,c,d);
}
Give the output of the following code snippet :
void main()
{
char str1[12]="Hello world";
char *str="Yellow World";
char *str2="%s %s";
printf(str2,str,str1);
}
Give the output of the following code snippet :
int main()
{
int ary[4] = {1, 2, 3, 4};
int *p = ary + 3;
printf("%d %d\n", p[-2], ary[p]);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20,c=5;
_asm
{
inc dword ptr[a]
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
mov ecx,10
and ecx,ebx
dec ecx
mov dword ptr[c],ecx
}
printf("%d",c);
}
Give the output of the following code snippet :
int main()
{
struct u
{
unsigned char x : 1;
unsigned int y : 4;
} p;
struct u un;
un.y = 2;
printf("%d\n",sizeof(p));
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 100, j = 5;
_asm
{
Label2: cmp dword ptr[i], 0
je Label1
mov eax, dword ptr[i]
sub eax, 1
mov dword ptr[i], eax
mov ecx, dword ptr[j]
add ecx, 1
mov dword ptr[j], ecx
mov edx, dword ptr[a]
add edx, dword ptr[j]
mov dword ptr[a], edx
jmp Label2
}
Label1:printf("%d %d", a, j);
}
Give the output of the following code snippet :
void print(...)
{
int i;
va_list marker;
va_start(marker,int);
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 :
void print(int num,int num2,...)
{
int i;
va_list marker;
va_start(marker,num2);
while((--num2) != 0)
{
i=va_arg(marker,int);
printf("%d ",i);
}
va_end(marker);
}
int main(int argc, char *argv[])
{
print(4,3,20,30);
}
Give the output of the following code snippet :
struct student
{
char *name;
};
struct student s[2], r[2];
void main()
{
s[0].name = "Jenn";
r = s;
printf("%s", r[0].name);
}
Give the output of the following code snippet :
float i;
void main()
{
(int)(double)i;
printf("%d",sizeof((double)i));
}
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()
{
char *MemAlloc;
MemAlloc = (char*)malloc(20 * sizeof(char) );
strcpy( MemAlloc,"SourceLens");
printf("%s",MemAlloc);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
extern int value;
void func(int);
/* Test1.c */
#include "Test1.h"
void func(int arg)
{
value=200;
printf ( "Output = %d\n", arg+value );
}
/* Test2.c */
#include "Test1.h"
static int arg=10;
void main ()
{
value = 300;
func(arg+value);
}
Give the output of the following code snippet :
void f(int a[][])
{
a[0][1] = 3;
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
printf("%d ", a[i][j]);
}
void main()
{
int a[2][2] = {0};
f(a);
}
Give the output of the following code snippet :
void main()
{
int a=30,c=-10,b=40;
_asm
{
mov eax,30
mov ebx,b
sub eax,dword ptr[b]
jo 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);
}
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
push 30
push 40
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
mov b,eax
}
printf("%d %d %d", a, b, c);
}
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.c,s.c)==0)
printf("%s",m.c);
else
printf("%s",strupr(m.c));
}
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 :
int main()
{
int y=100;
int const* z=&y;
y=200;
printf("%d",*z);
}
Give the output of the following code snippet :
void func(struct stud *stuobj);
struct stud
{
char name[10];
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 :
int main()
{
int arry[5]= {20,10,5,0};
arry[5]=10;
arry[6]=++(*arry);
printf("%d %d",&arry,sizeof(arry));
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
void func();
/* Test1.c */
#include "Test1.h"
static int value;
void func()
{
printf ( "Output = %d\n", value );
}
/* Test2.c */
#include "Test1.h"
static int value;
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
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);
}
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 func1();
void func()
{
value = 200;
func1();
printf("Output = %d\n",++value);
}
/* Test2.c */
#include"Test2.h"
void func1()
{
value = 200;
printf ( "Output = %d\n", ++value );
func();
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
void main ()
{
func();
}
Give the output of the following code snippet :
void main()
{
const char arry[10]="Hello";
char str[15]="World";
char* ptr=str;
*arry='Y';
ptr=arry;
printf("%s",ptr);
}
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 :
struct point
{
int x;
int y;
};
void fun(struct point*);
int main()
{
struct point p1 = {1, 2};
fun(p1);
}
void fun(struct point *p)
{
printf("%d\n", p -> x++);
}
Give the output of the following code snippet :
void main()
{
int i = 13, a = 10;
_asm
{
mov eax, dword ptr[i]
and eax, 80000001h
jns Label1
dec eax
or eax, 0FFFFFFFEh
inc eax
Label1 : test eax, eax
jne Label2
mov dword ptr[a], 12Ch
}
Label2: printf("%d", a);
}
Give the output of the following code snippet :
struct point
{
int x;
char c;
float y;
int z;
} ptr;
int main()
{
float* offset=&(((point*)0)->y);
printf("%d",offset);
}
Give the output of the following code snippet :
struct student
{
char *name;
} s;
struct student fun(void)
{
s.name = "Jenn";
return s;
}
void main()
{
struct student m = fun();
printf("%s ", m.name);
printf("%s\n", s.name);
}
Give the output of the following code snippet :
struct point
{
int x;
float y;
};
void fun(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
fun(p1);
}
void fun(struct point p[])
{
printf("%d %f\n", p->x, p[3].y);
}
Give the output of the following code snippet :
union p
{
int x;
char y;
};
int main()
{
union p p1[] = {1, 92, 3, 96};
union p *ptr1 = p1;
printf("%d\n",ptr1->x);
}
Give the output of the following code snippet :
void main()
{
int i = 0, a = 10;
_asm
{
Label2: cmp dword ptr[i], 0
jle Label1
mov eax, dword ptr[a]
add eax, 5
mov dword ptr[a], eax
Label1 : mov ecx, dword ptr[i]
add ecx, 2
mov dword ptr[i], ecx
cmp dword ptr[i], 6
jne Label2
}
printf("%d", a);
}
Give the output of the following code snippet with the following command line arguments :
>Test.c 100 200 300
int main(int argc, char *argv[])
{
int i=strlen(argv[3]);
int sum=0;
do
printf("%d ",atoi(argv[--argc])-atoi(argv[argc])-atoi(argv[argc]));
while(!argc);
}
Give the output of the following code snippet :
void main()
{
int ch=0,sum=0;
for (int num=20; num > 0; num >>=2)
{
sum= num < < 1 & ~(3*1-4);
}
printf("%d",sum);
}
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!=0)
{
sum+=i;
count++;
i=va_arg(marker,int);
}
va_end(marker);
return sum;
}
int main(int argc, char *argv[])
{
printf("%d",sum(2,3,4,5,6,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();
/* 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 :
struct node
{
int data;
struct node *next;
struct node *prev;
}*head;
void func( int num )
{
struct node *temp,*temp2;
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
temp->prev=NULL;
head=temp;
}
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
temp2->prev=temp;
}
}
void Delete(int num)
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=head->next;
head->prev=NULL;
}
else
{
if(temp->next==NULL)
temp->prev->next=NULL;
else
{
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
}
}
free(temp);
return;
}
temp= temp->next;
}
}
void display()
{
struct node *r;
r=head;
while(r->next!=NULL)
r=r->next;
while(r->prev!=NULL)
{
printf("%d ",r->data);
r=r->prev;
}
printf("\n");
}
void main()
{
func(100);
func(200);
func(300);
func(400);
Delete(100);
Delete(300);
func(500);
display();
}
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 :
int main()
{
int arry[5]= {1,2,3,4,5,6};
int *ptr;
ptr=&arry[1];
ptr++;
printf("%d ",*arry+2);
}
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;
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
int value = 100;
void main ()
{
printf ( "Output = %d", value );
}
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");
}
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 :
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 :
int main()
{
int a = 15, b = 10, c;
_asm
{
mov eax,a
mov ebx,b
mov edx,dword ptr[c]
xor eax,ebx
or eax,edx
dec edx
mov dword ptr[a],eax
mov dword ptr[b],edx
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
void main()
{
int x = 100, y = 200, max;
_asm
{
mov eax, dword ptr[x]
cmp eax, dword ptr[y]
jle Label1
mov eax, dword ptr[x]
add eax, dword ptr[y]
mov dword ptr[max], eax
jmp Label2
Label1 : mov eax, dword ptr[y]
sub eax, dword ptr[x]
mov dword ptr[max], eax
}
Label2: printf("%d", max);
}
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 :
void main()
{
char str[]="Hello world";
char *str1="Yellow World";
int n=strcmp(str,str1);
if(n)
printf("%d",++n);
else
printf("%d",n--);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 300;
/* Test1.c */
extern int value;
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void func();
void main ()
{
printf ( "Output = %d\n", value );
func();
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
struct node *prev;
}*head;
void func( int num )
{
struct node *temp,*temp2;
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
temp->prev=NULL;
head=temp;
}
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
temp2->prev=temp;
}
}
void Delete(int num)
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=head->next;
head->prev=NULL;
}
else
{
if(temp->next==NULL)
temp->prev->next=NULL;
else
{
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
}
}
free(temp);
return;
}
temp= temp->next;
}
}
void display()
{
struct node *r;
r=head;
while(r->next!=NULL)
r=r->next;
while(r->prev!=NULL)
{
printf("%d ",r->data);
r=r->prev->prev;
}
printf("\n");
}
void main()
{
func(100);
func(200);
func(300);
func(400);
Delete(100);
Delete(300);
func(500);
display();
}
Give the output of the following code snippet :
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 :
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!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
}
void main()
{
func(100);
func(200);
func(300);
func(400);
display();
}
Consider the given structure and state whether it is a self referencing structure :
struct node
{
int x;
struct node *next;
}*Head;
Give the output of the following code snippet :
void func(char *s)
{
printf("%s",s);;
}
void main()
{
char str[]="Hello World";
char *str1="Hello world";
str1= str1 +"New Program";
func(str1);
}
Give the output of the following code snippet :
#define row 3
#define col 3
void main()
{
int (*arr)[col];
arr=(int (*)[col])malloc(sizeof(row*sizeof(*arr)));
printf("%d",sizeof(arr));
}
Give the output of the following code snippet :
void main()
{
int a=2,c=10,b=30;
_asm
{
mov eax,1
mov ebx,a
sub eax,ebx
jb Label1
mov b,200
mov c,100
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void main()
{
int a[2][5] = {1, 2, 3, 0};
for (int i = 0; i < 1; i++)
for (int j = 0; j < 2; j++)
printf("%d ", *a[0]+1);
}
Give the output of the following code snippet :
union
{
int x;
char y;
} p;
int main()
{
p.y = 80;
printf("%c",p.y);
}
Give the output of the following code snippet :
void main()
{
int row=2,col=2;
int *arr;
int i,j;
arr=(int*)malloc(2*2*sizeof(int));
for(i=0; i< row; i++)
{
for(j=0; j< col; j++)
{
arr[i*col+j]=i*i;
printf("%d ",arr[i*col+j]);
}
}
}
Give the output of the following code snippet :
int main()
{
int a = 20, b = 10,c=2;
_asm
{
mov eax,esp
push ebx
mov ecx,esp
sub eax,ebx
mov b,eax
pop ebx
}
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;
void func();
/* Test1.c */
extern int value;
void func()
{
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.c"
void main ()
{
printf ( "Output = %d\n", value );
func();
}
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));
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value;
void func();
/* Test1.c */
extern int value;
void func()
{
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void main ()
{
printf ( "Output = %d\n", value );
func();
}
Give the output of the following code snippet :
typedef void v;
v func(int,int);
void main()
{
func(10,10);
}
v func(int x,int y)
{
printf("%d",x+y);
}
Give the output of the following code snippet :
int main()
{
int arry[][3]= {1,2,3,4,5,6};
printf("%d",**arry+3);
}
Give the output of the following code snippet :
void main()
{
int row=2,col=2;
int *arr;
int i,j;
arr=(int*)malloc(row*col*sizeof(int));
for(i=0; i< row; i++)
{
for(j=0; j< col; j++)
{
arr[i*col+j]=i+j;
printf("%d ",arr[i*col+j]);
}
}
}
Give the output of the following code snippet with the following command line arguments :
>Test.c Hello World
void func(char *arry[])
{
for(int i=1; i< =3; i++)
printf("%s ", (arry[i])+2);
}
int main(int argc, char *argv[])
{
func(argv);
return 0;
}
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!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(100);
AddNode(200);
ReverseList();
Display();
}
Give the output of the following code snippet with the following command line arguments :
>Test.c Hello World
int main(int argc, char *argv[])
{
printf("%s\n", argv[argc]);
return 0;
}
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 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
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, 0x10
}
printf("%d %d %d", a, b,c);
}
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 :
int main()
{
int arry[10]= {0};
arry[5]=10;
arry[6]=++(arry[5]);
printf("%d",arry[6]);
}
Give the output of the following code snippet :
int main()
{
int a=10, b=20,*ptr,*qtr;
ptr=&a;
qtr=&b;
*ptr=b++%--a;
*qtr=*ptr/a++;
printf("%d %d %d", a,*ptr,*qtr);
return 0;
}
Give the output of the following code snippet :
void func(struct stud *stuobj);
struct stud
{
int no;
int no2;
};
void main()
{
struct stud s= {1001,1002};
func(&s);
}
void func(struct stud *stuobj)
{
struct stud *s;
s=stuobj;
printf("%d",s->no);
}
Give the output of the following code snippet :
void 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 :
typedef struct student
{
char *a;
} stud;
void main()
{
struct s;
s.a = "Hello";
printf("%s", s.a);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax,a
mov ebx,b
and eax,ebx
xor eax,b
mov dword ptr[a],eax
}
printf("%d",a);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
}*head=0;
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;
}
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;
}
void main()
{
struct node *n;
add(100);
add(200);
addtoLoc(0,400);
addtoLoc(1,300);
display(n);
}
Give the output of the following code snippet :
void main()
{
char arry[10]="Hello";
char str[15]="World";
char* ptr=str;
*arry='Y';
ptr=arry;
printf("%s",ptr);
}
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)
{
value = 200;
func1(arg);
printf("Output = %d\n",arg+value);
}
/* Test2.c */
#include"Test2.h"
int value = 200;
void func1(int arg)
{
value = 100;
printf ( "Output = %d\n", arg+value );
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
void main ()
{
func(arg);
}
Give the output of the following code snippet :
struct node
{
char* data;
struct node *next;
}*head=0;
void addtoLoc( int n,char* num )
{
struct node *temp2,*temp;
temp2=head;
if(temp2==NULL)
{
printf("Empty List");
return;
}
for(int i=0; i< n; i++)
temp2=temp2->next;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=temp2->next;
temp2->next=temp;
}
void display(struct node *r)
{
r=head;
while(r!=NULL)
{
printf("%s ",r->data);
r=r->next;
}
}
void add( char* num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
head=temp;
}
void main()
{
struct node *n;
add("Hello");
add("World");
addtoLoc(0,"Prog");
display(n);
}
The elements in the following array, int arr[2]={1,2} are
< NIL>
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);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 100;
/* Test1.c */
int value = 200;
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 main()
{
int y=100;
const int x=y++;
printf("%d\n", ++x);
return 0;
}
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 :
void main()
{
int i = 0, a = 10;
_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], 3
jge Label2
cmp dword ptr[i], 1
jle Label3
mov dword ptr[a], 64h
jmp Label2
Label3 : jmp Label4
}
Label2:printf("%d %d", a, i);
}
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 :
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(1100);
}
Give the output of the following code snippet :
void func(int arr[][5])
{
**arr++;
printf("%d ",**arr+1);
}
int main()
{
int arry[][5]= {1,2,3,4,5,6};
func(arry);
printf("%d ",**arry+2);
}
Give the output of the following code snippet :
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]
sub eax, dword ptr[ecx]
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 DecToBin(int num)
{
if (num == 0)
{
return 0;
}
else
{
return (num % 2) + 10 * DecToBin(num / 2);
}
}
int main()
{
printf("%d",DecToBin(25));
}
Give the output of the following code snippet :
void main()
{
int a=100;
int b=200;
char str[10];
int x;
gcvt(25.3456,3,str);
printf("%s ",str);
}
Give the output of the following code snippet :
int main()
{
int x=100,y=200,z=0;
x>300?y=20;
x< 300?x=40:z=100;
printf("%d %d %d",x,y,z);
return 0;
}
Give the output of the following code snippet :
void main()
{
int a=40,c=50,b=30;
_asm
{
mov eax,30
mov ebx,dword ptr[b]
cmp eax,ebx
jge Label2
shr eax,1
and eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[c]
sub ecx,ebx
jns Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
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 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 :
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()
{
int arry[10]= {1,2,3,4,5,6};
int x=arry[5];
x++;
int y=6[arry];
y--;
int z=x+y;
z--;
printf("%d",++z);
}
Give the output of the following code snippet :
void func(int arr[])
{
*arr++;
printf("%d ",(arr[0]));
}
int main()
{
int n=10;
int arry[n]= {1,2,3,4,5,6};
func(arry);
}
Give the output of the following code snippet :
void f(int a[][2])
{
a[1][1] = 3;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
printf("%d ", a[i][j]);
}
void main()
{
int a[2][2] = {0};
f(a);
}
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=10,c=-10,b=10;
_asm
{
mov eax,10
mov ebx,b
sub eax,dword ptr[b]
jnle Label2
mov edx,dword ptr[c]
and 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);
}
Give the output of the following code snippet :
int main()
{
union site
{
char name[] = "SourceLens";
int no = 200;
};
union site *ptr;
printf("%d ", ptr->no);
printf("%s", ptr->name);
}
Give the output of the following code snippet :
void main()
{
unsigned int a=10;
unsigned int b=10;
int c = a < < 2;
int d = b < < 1;
printf("%d %d",c,d);
}
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.a);
return 0;
}
Give the output of the following code snippet :
void main()
{
int row=2,col=2;
int *arr;
int i,j;
arr=(int*)malloc(row*col*sizeof(int));
for(i=0; i< row; i++)
{
for(j=0; j< col; j++)
{
arr[i*col+j]=i*i;
printf("%d ",arr[i*col+j]);
}
}
}
Give the output of the following code snippet :
void main()
{
char s1[]="Hello World";
int len=sizeof(s1);
memset(s1,'#',len-15);
puts(s1);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
struct node *prev;
}*head;
void func( int num )
{
struct node *temp,*temp2;
if (head== NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=NULL;
temp->prev=NULL;
head=temp;
}
else
{
temp=head;
while (temp->next!=NULL)
temp=temp->next;
temp2=(struct node *)malloc(sizeof(struct node));
temp2->data=num;
temp2->next=NULL;
temp->next=temp2;
temp2->prev=temp;
}
}
void Delete(int num)
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=head->next;
head->prev=NULL;
}
else
{
if(temp->next==NULL)
temp->prev->next=NULL;
else
{
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
}
}
free(temp);
return;
}
temp= temp->next;
}
}
void display()
{
struct node *r;
r=head;
while(r->next!=NULL)
r=r->next;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->prev;
}
printf("\n");
}
void main()
{
func(100);
func(200);
func(300);
func(400);
Delete(100);
Delete(300);
Delete(400);
func(500);
display();
}
Consider the given statement from the below lines of code: What does it indicate?
root->prev=NULL;
struct node *root;
root = (struct node *) malloc( sizeof(struct node) );
root->next = NULL;
root->x = 5;
root->prev=NULL;
Head=root;
Give the output of the following code snippet :
int main()
{
float x=80.00;
double y=90.00;
if( x == y)
printf("%.2e %c",x,x);
else
printf("%g %c",y,y);
}
Give the output of the following code snippet :
int(*funcptr) (char a);
int myfunc(char a)
{
_asm
{
mov byte ptr [a],3Fh
mov al,byte ptr [a]
add al,6
mov byte ptr [a],al
}
printf("%c",a);
return 0;
}
int testCaller(int(*funcptr) (char a))
{
_asm
{
push 6Ch
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 i, j, k, sum = 0;
_asm
{
mov dword ptr[i], 0
mov dword ptr[j], 0FFFFFFFFh
mov dword ptr[k], 1
jmp Label1
Label3 : mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
Label1 : cmp dword ptr[i], 4
jg Label2
mov ecx, dword ptr[i]
add ecx, dword ptr[j]
add ecx, dword ptr[k]
mov dword ptr[sum], ecx
jmp Label3
}
Label2: printf("%d ", sum);
}
Give the output of the following code snippet :
int f()
{
int*p;
int x=100;
p=&x;
return *p;
}
void main()
{
int *ptr;
ptr=f();
printf("%d",*ptr);
}
Give the output of the following code snippet :
struct student
{
int age;
char name[25];
};
int main()
{
struct student c[] = { {12, "Jenn"},
{13, "Abby"}
};
printf("%d ", c[].age);
return 0;
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax, a, b
sub eax, ebx
mov c, eax
}
printf("%d", c);
}
Give the output of the following code snippet :
int main()
{
int c=10;
_asm
{
mov eax,10
mul 100
mov c, eax
}
printf("%d", c);
}
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->prev->data);
r=r->prev->prev;
}
}
void main()
{
func(100);
func(200);
func(300);
func(400);
display();
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
void fun(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4};
fun(p1);
}
void fun(struct point p[])
{
printf("%d\n", p->x);
}
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
js Label1
mov c,ebx
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int(*funcptr) (int a);
int myfunc(int a)
{
int sum=0;
a=20;
_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 output of the following code snippet :
void main()
{
int a=40,c=30,b=20;
_asm
{
mov eax,30
mov ebx,dword ptr[c]
sub eax,ebx
jnl Label2
xor eax,1
and eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[c]
sub ecx,ebx
jns Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int main()
{
enum Days {SUN,MON,TUES,WED,THURS,FRI,SAT};
Days day;
printf("%d",sizeof(day));
}
Give the output of the following code snippet :
int 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 :
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 :
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 :
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->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 main()
{
int a = 20, b = 20,c=2;
_asm
{
mov eax,dword ptr[a]
mov ebx,dword ptr[b]
shl eax,1
inc eax
mov dword ptr[a],eax
}
printf("%d",a);
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 5, sum = 0;
_asm
{
Label2: cmp dword ptr[i], 0
je Label1
mov eax, dword ptr[sum]
add eax, dword ptr[a]
mov dword ptr[sum], eax
mov ecx, dword ptr[i]
sub ecx, 1
mov dword ptr[i], ecx
mov edx, dword ptr[j]
add edx, 1
mov dword ptr[j], edx
mov eax, dword ptr[a]
add eax, dword ptr[j]
mov dword ptr[a], eax
jmp Label2
}
Label1:
printf("%d %d", a, sum);
}
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);
int arg = 10;
/* 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"
void main ()
{
func1(arg);
}
Give the output of the following code snippet :
void func(int arr[][])
{
**arr++;
printf("%d ",**arr);
}
int main()
{
int arry[][5]= {1,2,3,4,5,6};
func(arry);
printf("%d ",**arry+3);
}
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",*x);
}
Give the output of the following code snippet :
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}
Give the output of the following code snippet :
int main()
{
double *p = (double *)0;
printf("%p ",p);
p=p+1;
printf("%p",p);
}
Give the output of the following code snippet :
int func(int *x)
{
int *ptr;
int y=100;
ptr=x;
ptr=&y;
return *ptr;
}
void main()
{
int (*f[5])(int*);
int *a;
int b=200;
a=&b;
f[0]=func;
printf("%d",(*f)(a));
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 10, b = 10,c=10,d=10;
__asm
{
mov eax,Label1
mov dword ptr[c],eax
call dword ptr[c]
mov ebx,Label2
mov ecx,100
mov edx,25
jmp ebx
Label1 :
mov a, 20
mov d, ecx
ret
Label2 : mov b,edx
mov c,300
mov a,50
}
printf("%d %d %d %d", a,b,c,d);
}
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
jmp Label5
jmp Label5
jmp Label3
Label2 : mov dword ptr[a], 0C8h
Label3 : jmp Label4
jmp Label4
Label5 : mov dword ptr[a], 190h
}
Label4: printf("%d", a);
}
Give the output of the following code snippet :
struct temp
{
int a;
} s[5];
void func(struct temp*)
{
s[0].a = 5;
printf("%d ", s[0].a);
}
void main()
{
func(s);
printf("%d\t", s[0].a);
}
Give the output of the following code snippet :
int main()
{
int ary[2][3][4], j = 20;
ary[0][0] = &j;
printf("%d\n", *ary[0][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
push 50
push 70
push 80
mov ebx,30
mov eax, 40
mov ecx,60
call label1
add eax,ebx
mov a,eax
mov b,ebx
add esp, 20
jmp Label2
label1:
mov eax, dword ptr[esp + 4]
mov a, eax
add a, ebx
mov eax, dword ptr[esp + 12]
mov b, eax
mov eax, dword ptr[esp + 20]
xor edx,ecx
mov c,eax
sub edx,ecx
or 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)
{
int sum=0;
_asm
{
mov dword ptr [sum],14h
mov eax,dword ptr [i]
add eax,0Ah
mov dword ptr [i],eax
imul ecx,dword ptr [sum],0Ah
mov dword ptr [sum],ecx
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 :
int main()
{
void *p;
int a[4] = {1, 2, 3, 3};
p = &a[1];
int *ptr = a;
int n = (int *)p - ptr;
printf("%d\n", n);
}
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);
}
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 *f()
{
int*p;
int x=100;
p=&x;
return p;
}
void main()
{
int *ptr;
ptr=f();
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 a=-20,c=10,b=30;
_asm
{
mov eax,-20
mov ebx,a
sub eax,dword ptr[c]
jnae 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 :
union student
{
int no;
float no1;
double no2;
};
void main()
{
union student s= {10};
printf("%d",s.no2);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value;
void func();
/* Test1.c */
extern int value;
void func()
{
printf ( "Output = %d", value );
}
/* Test2.c */
void main ()
{
printf ( "Output = %d\n", value );
func();
}
Give the output of the following code snippet :
void main()
{
int a=20,c=10,b=30;
_asm
{
mov eax,30
mov ebx,a
sub eax,dword ptr[c]
jb Label2
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
je Label1
and eax,dword ptr[b]
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void main()
{
int a=10,c=20,b=10;
_asm
{
mov eax,20
mov ebx,a
sub eax,ebx
jbe Label2
or eax,c
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,eax
je Label1
or eax,50
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void main()
{
int a=10,b=20,c=30;
unsigned int d=12;
int x,y,z;
x=a && b && c;
y=a || b || c;
z=x && y | c;
printf("%d %d %d",x,~y,~d);
}
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]
mov ecx,c
and ecx,ebx
inc ecx
mov dword ptr[c],ecx
}
printf("%d",c);
}