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 :
void main()
{
int i = 10, k = 10, j = 2;
int *ary[2];
ary[0] = i;
ary[1] = j;
printf("%d\n", *ary[0]);
}
Give the output of the following code snippet :
void func(struct emp*);
struct emp
{
char name[20];
int age;
};
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 :
void main()
{
char *s = "SourceLens";
char *p = &s;
printf("%c %c", *(p+1), s[10]);
}
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 :
int main()
{
int a = 10, b = 20, c=2;
_asm
{
mov eax,a
mov ebx,b
mov c,eax
shl eax,dword ptr[c]
shl ebx,2
xor eax,ebx
mov dword ptr[a],ebx
mov dword ptr[b],eax
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
int main()
{
int i, *j, k;
_asm
{
mov dword ptr[i], 0Fh
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov eax, dword ptr[i]
add eax, dword ptr[ecx]
mov ecx, dword ptr[j]
cdq
imul dword ptr[ecx]
sub eax, dword ptr[i]
mov dword ptr[k], eax
}
printf("%d\n", k);
return 0;
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax,a
mov c,b
div ebx
mov dword ptr[a],ebx
mov dword ptr[b],eax
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
typedef struct
{
int no;
int no2;
stud *link;
} stud;
void main()
{
stud s;
s.no=10;
printf("%d",s.no);
}
Give the output of the following code snippet :
int ConvertToHex(long int binVal)
{
long int hexVal = 0, i = 1, rem=0;
while (binVal != 0)
{
rem = binVal % 10;
hexVal = hexVal + rem * i;
i = i * 2;
binVal = binVal / 10;
}
printf("%lX", hexVal);
return 0;
}
void main()
{
ConvertToHex(10001111);
}
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 :
struct Test
{
static int x: 2;
int y[10]:2;
} t;
void main()
{
t.x=10;
t.y=20;
printf("%d",t.y);
}
Give the output of the following code snippet :
void *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 :
int ConvertToHex(long int binVal)
{
long int hexVal = 0, i = 1, rem=0;
while (binVal != 0)
{
rem = binVal % 10;
hexVal = hexVal + rem * i;
i = i * 2;
binVal = binVal / 10;
}
printf("%lX", hexVal);
return 0;
}
void main()
{
ConvertToHex(10000);
}
Give the output of the following code snippet run with the following commandline arguments:
>Testfile.c one two three
/* Testfile.c */
int main(int argc, char **argv)
{
printf("%s\n", *++argv);
return 0;
}
Give the output of the following code snippet :
void main()
{
typedef unsigned int uint;
uint x=-100,y=200;
unsigned int a=300,b=400;
int z;
printf("%d",x-y/a+b);
}
Give the output of the following code snippet :
char *func(unsigned int num,int base)
{
static char bffer[33];
char *p=&bffer[sizeof(bffer)-1];
*p='\0';
do
{
*--p="0123456789"[num%base];
num/=base;
}
while(num!=0);
return p;
}
void main()
{
char *str;
str=func(3,2);
printf("%s",str);
}
Give the output of the following code snippet :
void main()
{
int a=30,c=20,b=-50;
_asm
{
mov eax,-10
mov ebx,dword ptr[b]
cmp eax,ebx
jle Label2
or eax,ebx
mov b,eax
Label2:
mov ecx,dword ptr[c]
sub ecx,ebx
jnz Label1
or eax,ecx
mov c,eax
}
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;
_asm
{
mov dword ptr [a],3Ah
mov eax,dword ptr [sum]
add eax,dword ptr [a]
mov dword ptr [sum],eax
mov ecx,dword ptr [a]
imul ecx
mov dword ptr [a],ecx
}
printf("%d",a);
return 0;
}
int testCaller(int(*funcptr) (int a))
{
_asm
{
push 3Dh
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 (*arr)[3];
int arry[3]= {1,2,3};
arr=arry;
printf("%d",*(*arr));
}
Give the output of the following code snippet :
int main()
{
float *Pa1,*Pa2,*Pa3;
float a1=10.25,b1=12.5;
Pa1=&a1;
Pa2=&b1;
*Pa3=*Pa1 - *Pa2;
printf("%f",*Pa3);
}
Give the output of the following code snippet :
void main()
{
int a[2][5] = {1};
for (int i = 0; i < 2; i++)
for (int j = 0; j < 1; j++)
printf("%d ", *a[1]+1);
}
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()
{
struct Temp
{
int one:1;
};
struct Temp var = {1};
printf("%d\n", var.one);
return 0;
}
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--;
}
}
Give the output of the following code snippet :
int main()
{
int a=10, b=20, c;
c = (a == 100 && b > 20);
printf("%d", c);
return 0;
}
Give the output of the following code snippet :
int main()
{
char *s;
char buf [] = "Hello World";
s = strchr (buf, 'l');
if (s != NULL)
printf ("Found %s", s);
else
printf("Not found");
return 0;
}
Give the output of the following code snippet :
void main()
{
FILE *fp,*fp1;
char x;
fp = fopen("Test.txt","w+");
fputs("Hello World", fp);
fseek( fp, 10, SEEK_SET );
fputs("Yello", fp);
fclose(fp);
fp1 = fopen("Test.txt","r");
while(1)
{
x = fgetc(fp);
if( feof(fp) )
{
break;
}
printf("%c", x);
}
fclose(fp1);
}
Give the output of the following code snippet :
int main()
{
int arry[3][3]= {1,2,3,4,5,6};
printf("%d",**arry+3);
}
Files Test1.c, Test1.h, Test2.c and Test3.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
extern int value;
void func();
void func1();
/* Test1.c */
#include "Test1.h"
void func()
{
value=200;
printf ( "Output = %d\n", ++value );
}
/* Test2.c */
#include "Test1.h"
void func1()
{
value=200;
func();
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
int value = 400;
void main ()
{
func();
}
Give the output of the following code snippet :
void f(int i)
{
printf("%d\n", i);
}
void (*func)(void) = f;
int main(int argc, char *argv[])
{
func(10);
return 0;
}
Which of the following operand can be applied to pointers p and q?Assuming initializations as
< NIL>
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
struct point func(struct point);
int main()
{
struct point p1 = {1, 2};
p1=func(p1);
printf("%d\n", p1.y);
}
struct point func(struct point p)
{
p.y=20;
return p;
}
Give the output of the following code snippet :
struct student
{
char *c;
int age;
};
void main()
{
struct student s= {"Jenn",15};
struct student m;
m=s;
char *rev=strrev(m.c);
printf("%s",rev);
}
Give the importance of the following lines of code in the given function?
while(r!=NULL)
{
printf("%d ",r->data);
r=r->prev;
}
void func()
{
struct node *r;
r=head;
while(r->next!=NULL)
r=r->next;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->prev;
}
}
Give the output of the following code snippet :
void main()
{
char str[]="Hello world";
char *str1="Hello world";
if(str==str1)
printf("%c",str+2);
else
printf("%c",*(str1+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->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 :
void main()
{
int a=20,c=20,b=-20;
_asm
{
mov eax,-30
mov ebx,dword ptr[b]
cmp eax,ebx
jl Label2
shr eax,1
and eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
jne Label1
or eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void func(float *i)
{
*i=200.5;
}
void func2(float i)
{
i=300.75;
}
int main()
{
float i=100.25;
func(&i);
func2(i);
printf("%.2f ", i);
}
Give the output of the following code snippet :
void main()
{
int i, sum = 0;
_asm
{
mov dword ptr[i], 0
jmp Label1
Label3 : mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
Label1 : cmp dword ptr[i], 3
jge Label2
mov ecx, dword ptr[i]
imul ecx, dword ptr[i]
add ecx, dword ptr[sum]
mov dword ptr[sum], ecx
jmp Label3
}
Label2: printf("%d", sum);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b =0, c=0,d=0;
__asm
{
push 10
push 20
push 30
mov ebx,50
mov eax, 40
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 + 4]
mov b, eax
or b,ebx
mov eax, dword ptr[esp + 8]
or edx,ecx
mov c,eax
and edx,ecx
mov d,ebx
ret
}
Label2:
printf("%d %d %d %d", a, b, c, d);
}
Consider the given lines of code: Which of the following values is essential to fix the links once sorting is executed?
else
{
temp3=temp1;
temp1=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, *j, k;
_asm
{
mov dword ptr[i], 0Dh
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov edx, dword ptr[ecx]
sub edx, 10
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]
add edx, dword ptr[eax]
mov dword ptr[k], edx
}
printf("%d\n", k);
}
Give the output of the following code snippet :
void func(int arr[][5])
{
**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 :
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]);
}
}
}
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"
int value = 300;
int arg;
void main ()
{
func(arg+value);
}
Give the output of the following code snippet :
int main()
{
int i=10, *j;
j = &i;
*j+=1;
printf("%d ", *j**j+i*j);
return 0;
}
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 :
int main()
{
int i=3, *j;
j = &i;
printf("%d\n", i**j);
return 0;
}
Give the output of the following code snippet :
struct
{
char *name;
union
{
char *sval;
} u;
} symtab[10];
void main()
{
symtab.u.sval="HelloWorld";
printf("%s",symtab.u.sval);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
int main()
{
struct point p = {1};
struct point p1 = {1,1};
if(p.y == p1.y)
printf("Equal\n");
else
printf("Not equal\n");
}
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 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 :
#define VAR 10
void func()
{
printf("%d ",VAR);
}
int main()
{
typedef int iptr;
static iptr *ptr,*qtr;
int *rptr;
int x=VAR;
int y=200;
ptr=&x;
qtr=&y;
printf("%d ",(*ptr)+(*qtr));
func();
}
Give the output of the following code snippet :
void main()
{
typedef unsigned int uint;
uint x=100,y=200;
unsigned int a=300,b=400;
int z;
printf("%d",x*y/a-b);
}
Give the output of the following code snippet :
int main()
{
int a = 10, b = 20, c;
_asm
{
mov eax,a
mov ebx,b
mov c,eax
shl eax,3
shl ebx,2
xor eax,ebx
mov dword ptr[a],ebx
mov dword ptr[b],eax
}
printf("%d %d",a,b);
}
Give the output of the following code snippet :
struct node
{
int x;
struct node *next;
}*Head;
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
void AddNode( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->x=num;
temp->next=Head;
Head=temp;
}
void Display()
{
struct node *r;
r=Head;
while(r!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(20);
AddNode(3);
Display();
SortList();
Display();
}
Give the output of the following code snippet:
int main()
{
char *arg[] = { "ab", "cd", "ef", "gh", "ij", "kl" };
printf("%c", **arg);
}
Give the output of the following code snippet :
void main()
{
char *s = "Hello";
char *p = s;
printf("%c\t%c", *p, s[3]);
}
Give the output of the following code snippet :
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", sizeof(a[1]));
}
Give the output of the following code snippet :
typedef struct stud *ptr;
{
int no;
int no2;
ptr link;
};
void main()
{
stud s;
s.no=10;
printf("%d",s.no);
}
Give the output of the following code snippet :
int main()
{
int 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 :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b = 0;
__asm
{
call Label2
mov a, 100
Label2 : mov b, 200
ret
mov a,200
}
printf("%d %d", a, b);
}
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";
ptrary= &p;
strcpy(q.name, p.name);
ptrary = &q;
printf("%s\n", ptrary->name);
return 0;
}
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);
}
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 :
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 :
int Mult(int first,...)
{
int prod=1, count=0,i=first;
int marker;
va_start(marker,first);
while(i!=0)
{
prod*=i;
count++;
i=va_arg(marker,int);
}
va_end(marker);
return prod;
}
int main(int argc, char *argv[])
{
printf("%d",Mult(2,3,0));
}
Give the output of the following code snippet :
char *func()
{
char *str=(int*)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 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(800);
}
Give the output of the following code snippet :
int func(int x)
{
int *ptr;
x=200;
ptr=&x;
return *ptr;
}
void main()
{
int (*f)(int);
f=func;
printf("%d",(f)(100));
}
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 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 :
int main ()
{
char *ptr="Hello";
printf("%s",ptr);
}
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 :
int main()
{
int (*ptr);
int val=10;
ptr=val;
printf("%d",*ptr);
}
Give the output of the following code snippet :
void fun(int *);
int main()
{
int i = 10, *p = &i;
fun(&i);
}
void fun(int *p)
{
printf("%f\n", *p);
}
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 a = 0;
int b = 0;
int c = 0;
_asm
{
mov eax, 100
push eax
mov ebx, 1000
push ebx
mov ecx, 10000
push ecx
mov ebx, dword ptr[esp+8]
mov a, ebx
mov ebx, dword ptr[esp+4]
mov b, ebx
mov ebx, dword ptr[esp]
mov c, ebx
add esp, 0x10
}
printf( "%d %d %d", a, b, c );
}
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);
}
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);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 300;
void func();
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
int func()
{
int*p;
int x=88;
p=&x;
return *p;
}
void main()
{
void *ptr;
int (*f)();
f=func;
printf("%c",f());
}
Give the output of the following code snippet :
union p
{
int x;
char y;
};
int main()
{
union p p1;
union p *ptr1 = &p1;
ptr1->x=100;
ptr1->y='C';
printf("%c\n",ptr1->x);
}
Give the output of the following code snippet :
float *func()
{
float *s;
s=(float*)calloc(1,sizeof(float));
*s=100.25;
return s;
}
void main()
{
float *s;
s=func();
printf("%.3f",*s);
}
Give the output of the following code snippet :
typedef struct stud *ptr;
struct stud
{
int no;
int no2;
ptr link;
};
void main()
{
stud s;
s.no=10;
printf("%d",s.no);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 300;
void func();
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
extern int value;
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Give the output of the following code snippet :
int(*funcptr) (char a);
int myfunc(char a)
{
_asm
{
mov byte ptr [a],4Dh
mov al,byte ptr [a]
add al,6
mov byte ptr [a],al
}
printf("%d",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 :
void main()
{
int a=20,c=20,b=10;
_asm
{
mov eax,10
mov ebx,dword ptr[c]
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
jne Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
void main()
{
char str[]="Hello world";
char *str1="Hello world";
if(str==str1)
printf("%s",str+2);
else
printf("%s",str1+5);
}
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
add eax,ebx
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 :
struct student
{
int mark1;
int mark2;
};
void main()
{
struct student stud;
stud.mark1=100;
stud.mark2=98;
struct student *s=&stud;
printf("%d",s->mark2);
}
Give the output of the following code snippet :
enum State {Working = 1, Failed = -1, Done};
int main()
{
printf("%d %d %d", Working, Failed, Done);
return 0;
}
Give the output of the following code snippet :
void main()
{
int ch=0,sum=0,i;
int num=300,n=10,temp;
temp=num;
while(temp!=0)
{
temp>>=2;
ch++;
}
printf("%d",ch);
}
Give the output of the following code snippet :
int main()
{
int (*p)[5];
int a[][5]= {1,2,3,4,5,6};
p=a;
int *q;
q=(int*)a;
printf("%d %d %d",**p+3,*q+5,**a);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value=100;
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
int value = 100;
void main ()
{
printf ( "Output = %d", value );
}
Give the output of the following code snippet :
void main()
{
int arry[10]= {};
printf("%d",*(arry+5));
}
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);
}
int main(int argc, char *argv[])
{
print('X','Y');
}
Give the output of the following code snippet :
const int* func(int i)
{
int x=i;
const int *ptr=&x;
return (ptr);
}
void main()
{
int a=10,b=20;
const int *qtr=func(a);
qtr=&b;
printf("%d",*qtr);
}
Give the output of the following code snippet :
int main()
{
int y=100;
const int x=y++;
printf("%d\n", x);
return 0;
}
Give the output of the following code snippet :
struct q
{
char *name;
};
struct q *ptrary[3];
int main()
{
struct q *p;
p->name = "Hello";
ptrary[0] = p;
p->name= "World";
ptrary[1] = p;
printf("%s\n", ptrary[]->name);
return 0;
}
Give the output of the following code snippet :
void main()
{
char s1[]="Hello \0World";
char *s2;
int len=sizeof(s1);
s2=(char*)malloc(len);
memmove(s2,s1,len);
puts(s2);
}
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 :
void main()
{
int x, *ptr1, y;
_asm
{
mov dword ptr[x], 14h
lea eax, [x]
mov dword ptr[ptr1], eax
mov ecx, dword ptr[x]
add ecx, 1
mov dword ptr[x], ecx
mov edx, dword ptr[ptr1]
mov eax, dword ptr[edx]
add eax, dword ptr[x]
mov dword ptr[y], eax
mov ecx, dword ptr[ptr1]
add ecx, 4
mov dword ptr[ptr1], ecx
}
printf("%d ", y);
}
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[3].x);
else
printf("%d\n", p1[3].y);
}
Give the output of the following code snippet :
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", strlen(a[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 */
static int value;
void func1();
/* Test2.h */
extern int value;
void func();
/* Test1.c */
#include "Test1.h"
void func()
{
printf("Output = %d\n",value);
}
/* Test2.c */
int value = 200;
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
#include "Test2.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
void f(int a[][2])
{
a[0][1] = 3;
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
printf("%d ", a[i][j]);
}
void main()
{
int a[2][2] = {0};
f(a);
}
Give the output of the following code snippet :
void disp(int num,...)
{
print(num,...);
}
void print(int num,...)
{
int i,k;
float j;
va_list marker;
va_start(marker,num);
j=va_arg(marker,double);
printf("%.2f ",j);
va_end(marker);
}
int main(int argc, char *argv[])
{
print(1,2.2,3.3,4.4);
}
Give the output of the following code snippet :
int main()
{
union site
{
char name[];
int no;
};
union site p= {100};
union site *ptr=&p;
printf("%d ", ptr->no);
printf("%s", ptr->name);
}
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+func();
int z=x+y;
printf("%d",z);
}
Give the output of the following code snippet :
int main()
{
struct u
{
unsigned int 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 :
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("\n",2,-1);
}
Give the output of the following code snippet :
void f(int i)
{
printf("%d\n", i);
}
void (*fptr)() = f;
void main()
{
fptr(10);
}
Give the output of the following code snippet :
void main()
{
int a=100;
int b=200;
char *c="12.50";
char str[10],st[10];
int x;
float val=10.25;
float res=atoi(c)+val;
itoa(100,st,16);
printf("%s %.2f",st,res);
}
Give the output of the following code snippet :
int main()
{
int a = 10;
int b = 20;
int c = 30;
_asm
{
push eax
push a
push b
mov ebx, dword ptr[esp]
mov a, ebx
pop b
pop eax
mov ebx, dword ptr[esp+4]
mov b,ebx
add esp, 0x10
}
printf( "%d %d",a,b);
}
Give the output of the following code snippet :
int main()
{
float *Pa1,*Pa2,*Pa3;
float a1=10.25,b1=12.5;
Pa1=&a1;
Pa2=&b1;
*Pa3=*Pa1**Pa2;
printf("%f",*Pa3);
}
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 ary[2][2];
ary[][] = {1, 2, 3, 4};
printf("%d", ary[1][0]);
}
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",strlen(str1));
}
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-2]+3);
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=(stud*)malloc(sizeof(stud));
s->no=1001;
func(s);
}
void func(struct stud *stuobj)
{
struct stud *s;
s=stuobj;
printf("%d",s->no);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b =0, c=0,d=0;
__asm
{
push 100
push 200
push 500
mov ebx,300
mov eax, 400
call label1
add esp, 12
jmp Label2
label1:
mov d,eax
mov eax, dword ptr[esp + 4]
mov a, eax
mov eax, dword ptr[esp + 8]
mov b, eax
mov eax, dword ptr[esp + 12]
sub eax,ebx
mov c,eax
ret
}
Label2:
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
void print(char* first,...)
{
int sum=0, count=0,i;
va_list marker;
va_start(marker,first);
do
{
i=va_arg(marker,int);
printf("%d ",i);
}
while(i!=6);
va_end(marker);
}
int main(int argc, char *argv[])
{
print("Test",2,4,6,-1);
}
Give the output of the following code snippet :
int main()
{
char ch = 'c';
char *chptr = &ch;
printf("%f",*chptr);
}
Give the output of the following code snippet :
void main()
{
int a = 5;
_asm
{
mov dword ptr[ebp - 0D0h], 5
cmp dword ptr[ebp - 0D0h], 1
je Label1
cmp dword ptr[ebp - 0D0h], 5
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 :
int main()
{
int *Pa1, *Pa2, *Pa3;
int a1, b1,c;
_asm
{
mov dword ptr[a1], 0Ah
mov dword ptr[b1], 0Ch
lea eax, [a1]
mov dword ptr[Pa1], eax
lea ecx, [b1]
mov dword ptr[Pa2], ecx
mov edx, dword ptr[Pa1]
mov eax, dword ptr[Pa2]
mov ecx, dword ptr[edx]
imul ecx, dword ptr[eax]
mov dword ptr[c], ecx
lea edx, [c]
mov dword ptr[Pa3], edx
}
printf("%d", *Pa3);
}
Give the output of the following code snippet :
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
struct student *m = &s;
printf("%d", sizeof(m));
}
Give the output of the following code snippet :
int 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(10);
}
Give the output of the following code snippet :
int main()
{
int a = 15, b = 10, c;
_asm
{
mov eax,a
mov ebx,b
xor eax,ebx
or eax,ebx
dec 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 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]);
}
}
}
Give the output of the following code snippet :
void func(int i)
{
void *j;
j=&i;
printf("%d",*j);
}
void main()
{
int x=10;
func(x);
}
Give the output of the following code snippet :
#define offset(type,mem)(int)&(((type*)0)->mem)
int main()
{
struct u
{
char x;
int y;
float z;
} p;
int offx,offy,offz;
offx=offset(struct u,x);
printf("%d ", offx);
offy=offset(struct u,y);
printf("%d ", offy);
offz=offset(struct u,z);
printf("%d ", offz);
}
Give the output of the following code snippet :
int main()
{
enum Days {SUN,MON,TUES,WED,THURS,FRI,SAT};
Days day;
printf("%d %d",sizeof(Days),WED++ + --THURS);
}
Give the output of the following code snippet :
void main()
{
char *s = "HelloWorld";
char *p = s * 3;
printf("%s %c", *p, s[1]);
}
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 (*arr)[3];
int arry[3]= {1,2,3};
arr=&arry;
printf("%d",*(*arr)+1);
}
Give the output of the following code snippet :
void main()
{
int (*a)[2] = {1, 2, 3, 0};
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
printf("%d ", **a);
}
Give the output of the following code snippet :
int main()
{
int x=100,y=200,z=0;
x< 300?y=20:z=30;
x< =300?x=40:y;
printf("%d %d %d",x,y,z);
return 0;
}
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]
sub ecx,10
and ecx,ebx
or ecx,ebx
mov c,ecx
}
printf("%d",c);
}
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
ret
End : add esp, 0xC
}
printf("%d %d %d", a, b, c);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
}*head;
void func( 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);
r=r->next;
}
}
void main()
{
struct node *n;
func(100);
func(200);
func(300);
display(n);
}
Give the output of the following code snippet :
int main()
{
int c=10;
_asm
{
mov eax,10
mov ebx,20
mul ebx
mov c, eax
}
printf("%d", c);
}
Give the output of the following code snippet :
struct node
{
int data;
struct node *next;
}*head=0;
void display(struct node *r)
{
r=head;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
}
void add( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
head=temp;
}
int Delete(int num)
{
struct node *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=temp->next;
free(temp);
return 1;
}
else
{
prev->next=temp->next;
free(temp);
return 1;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return 0;
}
void main()
{
struct node *n;
add(100);
add(200);
display(n);
add(300);
Delete(100);
Delete(200);
display(n);
}
Give the output of the following code snippet :
void func( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
temp->prev=NULL;
while(head!=NULL)
head=head->next;
head=temp;
}
void display()
{
struct node *r;
r=head;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
}
void main()
{
func(100);
func(200);
func(300);
func(400);
display();
}
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"
int value = 100;
void main ()
{
printf ( "Output = %d", value );
}
Give the output of the following code snippet :
int main()
{
int a = 1;
_asm
{
mov eax, dword ptr[a]
mov dword ptr[ebp - 0D0h], eax
cmp dword ptr[ebp - 0D0h], 1
je Label1
cmp dword ptr[ebp - 0D0h], 2
je Label2
cmp dword ptr[ebp - 0D0h], 3
je Label3
jmp Label4
Label1 : mov dword ptr[a], 2
Label2 : mov dword ptr[a], 3
jmp Label4
Label3 : mov eax, dword ptr[a]
add eax, 4
mov dword ptr[a], eax
}
Label4 : printf("%d", a);
}
Give the output of the following code snippet :
int main()
{
int i=5, *j, k;
j = &i;
*j+=1;
printf("%d\n", i**j-*j);
return 0;
}
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
js Label1
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int mul(int a, int b)
{
return a * b;
}
void main()
{
int *fptr;
fptr = mul;
printf("%d",fptr(2, 3));
}
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 _tmain(int argc, _TCHAR* argv[])
{
int a = 20, b = 30, c=40,d=50;
__asm
{
push 10
mov ebx,d
push ebx
mov ebx,c
push ebx
mov ebx,b
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 :
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
s->c = "SourceLens";
printf("%s", m.c);
}
Give the output of the following code snippet :
void main()
{
char arry[10]="Hello";
char str[15]="World";
const char* ptr=str;
*str='Y';
printf("%s",str);
}
Give the output of the following code snippet :
int _tmain(int argc, _TCHAR* argv[])
{
int a = 0, b = 0;
__asm
{
mov eax,Label1
call eax
mov ebx,Label2
jmp ebx
Label1 :
mov a, 100
ret
Label2 : mov b, 200
}
printf("%d %d", a,b);
}
Give the output of the following code snippet :
void main()
{
int x = 1, y = 0, z = 5;
int a = x & y || z ^ y;
printf("%d", a);
}
Give the output of the following code snippet :
void main()
{
struct student
{
int age;
int id;
};
struct student s= {20,1001,30,1002};
int ch;
char str[10];
FILE *fp,*fp1;
fp=fopen("Test.txt","r");
fwrite(&s,sizeof(s),1,fp);
fclose(fp);
fp1=fopen("Test.txt","r");
struct student s1;
fread(&s1, sizeof(s1), 1, fp1);
printf("%d",s1.age);
fclose(fp1);
}
Give the output of the following code snippet :
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);
SortList();
AddNode(20);
AddNode(3);
AddNode(100);
AddNode(50);
Display();
}
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 :
int main()
{
int x=100,y=200,z=0;
x>300?y=20:x=300;
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()
{
char *s= "hello";
char *p = s;
printf("%d %d", p[1], s[1]);
}
Give the output of the following code snippet :
int(*funcptr) (int a);
int myfunc(int a)
{
int sum=0;
_asm
{
mov dword ptr [a],32h
mov eax,dword ptr [sum]
add eax,dword ptr [a]
mov dword ptr [sum],eax
mov ecx,dword ptr [a]
imul ecx
mov dword ptr [a],ecx
}
printf("%d",a);
return 0;
}
int testCaller(int(*funcptr) (int a))
{
_asm
{
push 32h
call dword ptr [funcptr]
add esp,4
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
testCaller(myfunc);
return 0;
}
Give the output of the following code snippet :
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 :
union Temp
{
int x;
float y;
char z;
};
void main()
{
union Temp t1;
t1.x=100;
printf("%d",t1.z);
}
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 :
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 :
int main()
{
int a = 10;
_asm
{
mov eax,100
mov ebx,200
sub eax,eax
mov a,eax
}
printf("%d", a);
}
Give the output of the following code snippet :
int main()
{
char *p=0;
printf("%d",p);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
void fun(struct point p[])
{
printf("%d %d\n", p[1].x,(p + 1)->y);
}
int main()
{
struct point p1[] = {1};
fun(p1);
}
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 :
void main()
{
char str1[15]="Hello World";
char str[10]="Yellow";
char str2[10]="\0World";
strcat(str,str2);
printf("%d %c",strlen(str1),"HelloWorld"[5]);
}
Give the output of the following code snippet :
void main()
{
char *a[10] = {"Yellow","Jello","Hello"};
for (int i = 0; i < = 3; i++)
printf("%s ", (a[i]));
}
Give the output of the following code snippet :
typedef struct student
{
char *a;
} stud;
void main()
{
struct stud s;
s.a = "Hello";
printf("%s", s.a);
}
Give the output of the following code snippet :
int main()
{
double *ptr = (double *)100;
ptr = ptr + 2;
printf("%u", 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[b]
jnc Label2
xor eax,c
mov b,eax
Label2:
mov ecx,dword ptr[a]
cmp eax,ecx
jne Label1
and eax,30
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
struct q
{
char *name;
struct q *next;
};
struct q *ptrary[10];
int main()
{
struct q *p;
p->name = "Hello";
ptrary[0] = p;
printf("%s\n", ptrary[0]->name);
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(2));
}
Give the output of the following code snippet :
typedef struct stud
{
int no;
int no2;
stud *link;
} stud;
void main()
{
stud s;
s.no=1001;
printf("%d",s.no);
}
Give the output of the following code snippet :
void main()
{
int a=100;
int b=200;
char str[10];
int x;
gcvt(25.3456,2,str);
printf("%s ",str);
}
Give the output of the following code snippet :
void main()
{
int x=10,y=20,arr[3],i;
for(i=0; i< 3; i++)
{
arr[i]=++x;
if(arr[i]!=x++ || arr[i]==++x)
printf("Hello ");
else
printf("World");
break;
}
}
Give the output of the following code snippet :
void main()
{
int a = 10,*ptr;
ptr=(int*)malloc(a*sizeof(int));
ptr=&a;
printf("%d",*ptr);
}
Give the output of the following code snippet :
int main()
{
int *Pa1 = 0;
int *Pa2 = 0;
int *Pa3 = 0;
int c = 0;
int a, b;
_asm
{
mov dword ptr[a], 0Ah
mov dword ptr[b], 14h
lea eax, [a]
mov dword ptr[Pa1], eax
lea ecx, [b]
mov dword ptr[Pa2], ecx
mov edx, dword ptr[Pa1]
mov eax, dword ptr[edx]
mov ecx, dword ptr[Pa2]
add eax, dword ptr[ecx]
mov dword ptr[c], eax
lea edx, [c]
mov dword ptr[Pa3], edx
}
printf("%d", *Pa3);
}
Give the output of the following code snippet :
void main()
{
int x=10,y=20;
int z=x+y;
int const* ptr=&z;
z++;
printf("%d",*ptr);
}
Give the output of the following code snippet :
struct point
{
int x;
int y;
};
struct point func(struct point);
int main()
{
struct point p1 = {1, 2};
p1.y=func(p1);
printf("%d\n", p1.y);
}
struct point func(struct point p)
{
p.y=20;
return p;
}
Give the output of the following code snippet :
int main()
{
int a=10, b=20, c,d,e;
c = (a == 100 && b >= 10);
c= a--*a++;
d=a+++b--/c++;
e=d++/c---a+++b;
printf("%d %d %d", c,d,e);
return 0;
}
Give the output of the following code snippet :
struct p
{
int x;
int y;
};
int main()
{
struct p p1[] = {10,20};
struct p *ptr1 = p1;
int x = (sizeof(p1) / sizeof(ptr1));
if (x == 1)
printf("%d\n", ptr1->x);
else
printf("%d",x);
}
Give the output of the following code snippet :
void main()
{
int a = 10;
_asm
{
mov eax, dword ptr[a]
add eax, 5
mov dword ptr[ebp - 0D0h], eax
cmp dword ptr[ebp - 0D0h], 5
je Label1
cmp dword ptr[ebp - 0D0h], 0Ah
je Label2
cmp dword ptr[ebp - 0D0h], 0Fh
je Label3
jmp Label4
Label1 : mov eax, dword ptr[a]
add eax, 0Ah
mov dword ptr[a], eax
Label2 : mov eax, dword ptr[a]
add eax, 32h
mov dword ptr[a], eax
Label3 : mov dword ptr[a], 64h
}
Label4: printf("%d", a);
}
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);
}
Files Test1.c, Test1.h, Test2.c and Test3.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
extern int value;
void func();
void func1();
/* Test1.c */
#include "Test1.h"
int value = 300;
void func()
{
value=200;
printf ( "Output = %d\n", ++value );
func1();
}
/* Test2.c */
#include "Test1.h"
void func1()
{
value=200;
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
int main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
_asm
{
mov eax, 10
push eax
mov ebx, 20
push ebx
mov ecx, 30
push ecx
push 200
push 300
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);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value=300;
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
extern int value = 100;
void main ()
{
printf ( "Output = %d", value );
}
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 :
int main()
{
float x=80.00;
double y=90.00;
if( x > y)
printf("%.2f",sqrt(x));
else
printf("%.2g",sqrt(y));
}
Give the output of the following code snippet :
void print(int num,...)
{
int i;
va_list marker;
va_start(marker,num);
while((--num) != 0)
{
i=va_arg(marker,int);
printf("%d ",i);
}
va_end(marker);
}
int main(int argc, char *argv[])
{
print(4,10,20,30);
}
Give the output of the following code snippet :
int(*funcptr) (char a);
int myfunc(char a)
{
_asm
{
mov dword ptr [a],42h
}
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 = 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
mov dword ptr[c],ecx
}
printf("%d",c);
}
Give the output of the following code snippet :
struct q
{
char *name;
};
struct q *ptrary[3];
int main()
{
struct q *p;
p->name = "Hello";
ptrary[0] = p;
p->name= "World";
ptrary[1] = p;
printf("%s\n", ptrary[0]->name);
return 0;
}
Give the output of the following code snippet :
void main()
{
struct temp
{
int a;
char b;
struct temp1
{
float d;
} p;
};
struct temp st = {1,'A','i',1.8};
printf("%d %c %c %f",st.a,st.b,st.p.c,st.p.d);
getch();
}
Files Test1.c, Test1.h, Test2.c, Test2.h and Test3.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
void func1(int);
extern int arg = 10;
/* Test2.h */
extern int value;
void func(int);
/* Test1.c */
#include"Test2.h"
void func1(int);
void func(int arg)
{
func1(arg);
value = 200;
printf("Output = %d\n",arg+value);
}
/* Test2.c */
#include"Test2.h"
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);
func1(arg);
}
Give the output of the following code snippet :
struct node
{
int x;
struct node *next;
}*Head;
void SortList()
{
node *temp1,*temp2,*temp3,*temp4,*temp5;
temp4=NULL;
while(temp4!=Head->next)
{
temp3=temp1=Head;
temp2=temp1->next;
while(temp1!=temp4)
{
if(temp1->x > temp2->x)
{
if(temp1==Head)
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
Head = temp2;
temp3=temp2;
}
else
{
temp5=temp2->next;
temp2 -> next=temp1;
temp1->next=temp5;
temp3->next = temp2;
temp3=temp2;
}
}
else
{
temp3=temp1;
temp1=temp1->next;
}
temp2=temp1->next;
if(temp2 == temp4)
temp4=temp1;
}
}
}
void AddNode( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->x=num;
temp->next=Head;
Head=temp;
}
void Display()
{
struct node *r;
r=Head;
while(r->next!=NULL)
{
printf("%d ",r->x);
r=r->next;
}
printf("\n");
}
int main()
{
AddNode(10);
AddNode(5);
AddNode(6);
AddNode(20);
AddNode(3);
AddNode(100);
AddNode(50);
SortList();
Display();
}
Give the output of the following code snippet :
void main()
{
char s1[]="Hello \0World";
char *s2;
int len=sizeof(s1);
s2=(char*)malloc(len);
memcpy(s2,s1,len);
puts(s2);
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value;
void func();
/* Test1.c */
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
extern int value;
void main ()
{
func();
printf ( "Output = %d\n", value );
}
Which of the following is the indirection or the dereferencing operator in C?
< NIL>
Give the output of the following code snippet :
struct stud
{
int no;
int no2;
struct emp *link;
};
struct emp
{
int id;
struct emp *link2;
};
typedef struct stud *ptr;
typedef struct emp *qtr;
void main()
{
ptr s=(stud *)malloc(sizeof(struct stud));
s->no=10;
printf("%d",s->no);
}
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 address of a as 500
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
printf("%d %d", p,a);
}
Give the output of the following code snippet :
void main()
{
int a[10] = {1};
printf("%d %d", sizeof(a),a);
};
Give the output of the following code snippet :
int main()
{
int a = 20;
int b = 20;
if ((a >> 1) == (a * 2))
printf("True ");
else
printf("False");
}
Give the output of the following code snippet :
int main()
{
int i = 3, a = 10, j = 5;
_asm
{
Label2: cmp dword ptr[i], 5
je Label1
mov eax, dword ptr[j]
imul eax, dword ptr[j]
add eax, dword ptr[a]
mov dword ptr[a], eax
mov ecx, dword ptr[a]
sub ecx, 1
mov dword ptr[a], ecx
mov edx, dword ptr[j]
add edx, 1
mov dword ptr[j], edx
mov eax, dword ptr[i]
add eax, 1
mov dword ptr[i], eax
jmp Label2
}
Label1:
printf("%d", a);
}
Give the output of the following code snippet :
int main()
{
int i = 0, a = 105;
_asm
{
Label3: cmp dword ptr[i], 3
jge Label2
mov eax, dword ptr[a]
add eax, 0Ah
mov dword ptr[a], eax
mov ecx, dword ptr[i]
add ecx, 1
mov dword ptr[i], ecx
cmp dword ptr[a], 1Eh
jne Label1
jmp Label2
Label1 : jmp Label3
}
Label2: printf("%d %d", a, i);
}
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 :
union Test
{
char str[20];
};
int main()
{
union Test st1, *st2;
strcpy(st1.str, "Hello");
st2 = st1;
st1.str[0] = 'J';
printf("%s",st2.str);
}
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
jne Label1
mov ecx, dword ptr[i]
sub ecx, 1
mov dword ptr[i], ecx
jmp Label2
} Label1:
printf("%d", a);
}
Give the output of the following code snippet :
union
{
int x;
char y;
} p;
int main()
{
p.x = 10;
printf("%d\n", sizeof(p));
}
Give the output of the following code snippet :
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 :
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
or eax,b
xor eax,a
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 main()
{
int *MemAlloc;
MemAlloc = (char*)malloc(20* sizeof(char));
strcpy( MemAlloc,"Hello");
printf("%s",MemAlloc+1);
}
Give the output of the following code snippet :
void main()
{
int a=-128,c=0;
_asm
{
mov eax,-150
sub eax,a
js Label1
mov c,eax
}
Label1: printf("%d",c);
}
Give the output of the following code snippet :
float i;
void main()
{
(int)(double)i;
printf("%d",sizeof((int)i));
}
Give the output of the following code snippet :
int main()
{
char str1[15] = "Hello World";
char ch = 'W';
char *str;
str=strchr(str1,ch);
printf(6+"Hello World");
return 0;
}
Give the output of the following code snippet :
int main()
{
const int ary[4] = {1, 2, 3, 4};
int *p;
p = ary + 3;
*p = 10;
printf("%d\n", ary[3]);
}
Give the output of the following code snippet :
void first()
{
printf("Func1");
}
void second()
{
printf("Func2 ");
first();
}
void main()
{
void (*ptr)();
ptr = first;
ptr();
}
Give the output of the following code snippet :
int ConvertToHex(long int binVal)
{
long int hexVal = 0, i = 1, rem=0;
while (binVal != 0)
{
rem = binVal % 10;
hexVal = hexVal + rem * i;
i = i * 2;
binVal = binVal / 10;
}
printf("%lX", hexVal);
return 0;
}
void main()
{
ConvertToHex(11001101);
}
Give the output of the following code snippet :
void main()
{
int a=40,c=30,b=10;
_asm
{
mov eax,40
mov ebx,dword ptr[c]
sub eax,ebx
ja Label2
and eax,c
and eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
je Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
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 node
{
int data;
struct node *next;
}*head=0;
void display(struct node *r)
{
r=head;
while(r!=NULL)
{
printf("%d ",r->data);
r=r->next;
}
}
void add( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
temp->next=head;
head=temp;
}
int Delete(int num)
{
struct node *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=temp->next;
free(temp);
return 1;
}
else
{
prev->next=temp->next;
free(temp);
return 1;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return 0;
}
void main()
{
struct node *n;
add(100);
add(200);
add(300);
add(400);
Delete(100);
display(n);
}
Give the output of the following code snippet :
int main()
{
int *x;
*x=100;
printf("%d",x);
}
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 :
void main()
{
int a=40,c=30,b=20;
_asm
{
mov eax,10
mov ebx,dword ptr[c]
cmp eax,ebx
jnl Label2
shl eax,1
and eax,dword ptr[a]
mov b,eax
Label2:
mov ecx,dword ptr[a]
sub ecx,ebx
js Label1
and eax,ecx
mov c,eax
}
Label1: printf("%d %d",b,c);
}
Give the output of the following code snippet :
int 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 func(int i)
{
printf("%d ",i);
}
void func2(int i)
{
printf("%d ",i);
}
void func3()
{
printf("%d ",i);
}
void main()
{
int x=10;
func(x);
func2(x);
func3();
}
Give the output of the following code snippet :
int main()
{
int i, *j, k;
_asm
{
mov dword ptr[i], 5
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov edx, dword ptr[ecx]
add edx, 1
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 :
void main()
{
struct student
{
int age;
int id;
};
struct student s= {20,1001};
int ch;
char str[10];
FILE *fp,*fp1;
fp=fopen("Test.txt","w");
fwrite(&s,sizeof(s),1,fp);
fclose(fp);
fp1=fopen("Test.txt","r");
struct student s1;
fread(&s1, sizeof(s1), 1, fp1);
printf("%d %d",s1.age,s1.id);
fclose(fp1);
}
Give the output of the following code snippet :
int main()
{
int arry[][]= {1,2,3,4,5,6};
printf("%d",**arry+3);
}
Give the output of the following code snippet :
int main()
{
int a = 20, b = 10,c=2;
_asm
{
mov eax,esp
push ebx,10
mov ecx,esp
sub eax,ecx
mov b,eax
add esp,4
}
printf("%d",b);
}
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, 3
mov dword ptr[i], ecx
cmp dword ptr[i], 9
jne Label2
}
printf("%d", a);
}
Give the output of the following code snippet :
struct student
{
char *name;
};
struct student s[2];
void main()
{
s[0].name = "Jenn";
s[1] = s[0];
printf("%s %s", s[0].name, s[1].name);
}
Which of the following is actually passed when an array name is passed as an argument to a function?
< NIL>
Give the output of the following code snippet :
struct q
{
char *name;
struct q *next;
};
struct q *ptrary;
int main()
{
struct q *p;
p->name = "Hello";
ptrary = &p;
printf("%s\n", p->name);
return 0;
}
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);
}
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()
{
value = 200;
}
/* Test2.c */
#include "Test1.h"
void func1()
{
printf ( "Output = %d\n", ++value );
}
/* Test3.c */
#include "Test1.h"
void main ()
{
func1();
func();
}
Give the output of the following code snippet :
struct p
{
char *name;
struct p *next;
};
struct p *ptrary;
int main()
{
struct p p, q;
p.name = "SourceLens";
p.next=NULL;
ptrary= &p;
strcpy(q.name, p.name);
ptrary = &q;
printf("%s\n", ptrary->next);
return 0;
}
Give the output of the following code snippet :
void main()
{
int 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 with the following command line arguments :
>Test.c Hello World Program
int main(int argc, char *argv[])
{
int i=strlen(argv[3]);
int sum=0;
printf("%c %d",argv[2][i],i);
}
Give the output of the following code snippet :
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=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 :
struct student
{
char *name;
};
void main()
{
struct student s[2];
s[1] = s[0] = "Jenn";
printf("%s %s", s[0].name, s[1].name);
}
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 + 4]
mov a, eax
add a, ebx
mov eax, dword ptr[esp + 8]
mov b, eax
mov eax, dword ptr[esp + 12]
xor edx,ecx
mov c,eax
sub edx,ecx
add edx,10
mov d,edx
ret
}
Label2:
printf("%d %d %d %d", a, b, c, d);
}
Give the output of the following code snippet :
int main()
{
int i, *j, k;
_asm
{
mov dword ptr[i], 0Ah
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov edx, dword ptr[i]
imul edx, dword ptr[ecx]
mov eax, dword ptr[j]
imul edx, dword ptr[eax]
mov dword ptr[k], edx
}
printf("%d\n", k);
return 0;
}
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')
{
str[i]='\0';
count++;
strrev(str);
printf("%s %d",str,count);
i=0;
}
else
str[i++]=ch;
}
fclose(fp);
}
Give the output of the following code snippet :
int main()
{
int i, *j, k;
_asm
{
mov dword ptr[i], 10
lea eax, [i]
mov dword ptr[j], eax
mov ecx, dword ptr[j]
mov eax, dword ptr[i]
sub eax, dword ptr[ecx]
add ecx, dword ptr[i]
mov ecx, dword ptr[j]
cdq
imul dword ptr[ecx]
add eax, dword ptr[i]
mov dword ptr[k], eax
}
printf("%d\n", k);
return 0;
}
Give the output of the following code snippet :
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int *r = &p;
printf("%d", (**r));
}
Files Test1.c, Test1.h, Test2.c are in same directory with the content given below. All files are in the same project of a console application. Predict the output of the program.
/* Test1.h */
int value = 300;
void func();
/* Test1.c */
extern int value;
void func()
{
int value = 200;
printf ( "Output = %d", value );
}
/* Test2.c */
#include"Test1.h"
void func() {};
void main ()
{
printf ( "Output = %d\n", value );
func();
}
Give the output of the following code snippet :
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 :
void main()
{
char s1[]="Hello World";
int len=sizeof(s1);
memset(s1,'#',len-10);
puts(s1);
}
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);
}