#include <iostream>
#include<stdio.h>
using namespace std;
void func(int**x)
{
printf("%d",**x);
}
int main() {
int arr[2][2]={2,3,4,5};
int *aptr=0;
aptr=&arr[2][1];
func(&aptr);
return 0;
}
Ans: 0
2)
#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
int x=3,*y,**z;
y=&x;
z=&y;
printf("%d%d%d",*y,**z,*(*z));
}
Ans: 333
3)#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
int arr[]={1,2,3,4,5};
int *ptr;
ptr=(int*)((char*)arr+(4*sizeof(int)));
*ptr=*ptr*+*ptr;
printf("%d",*ptr+4);
}
ans: 29
4)#include <iostream>
#include<stdio.h>
using namespace std;
void fun(int x[],int y)
{
x[0]+=y;
x[2]+=y;
x[4]+=y;
y+=1;
}
int main()
{
int arr[5]={1,2,3,4,5};
int i,b=2;
fun(arr,b);
for(i=0;i<5;i++)
printf("%d%d",arr[i],b);
return 0;
}
Ans: 3222524272
5)#include <iostream>
#include<stdio.h>
using namespace std;
int mul(int x,int y)
{
return(x*y);
}
int main()
{
int x=3,y=4;
int (*ptr)(int,int);
ptr=mul;
printf("value =%d",(*ptr)(x,y));
return 0;
}
Ans: Value 12
6)#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
int India=10;
int Pakisthan=20;
++India==0||++Pakisthan==30;
printf("\n%d,%d",India,Pakisthan);
return 0;
}
Ans: 11,21
7)#include <iostream>
#include<stdio.h>
using namespace std;
int main(void)
{
int a[][3]={1,2,3,4,5,6};
int (*ptr)[3]=a;
printf("%d%d",(*ptr)[1],(*ptr)[2]);
++ptr;
printf("%d%d\n",(*ptr)[1],(*ptr)[2]);
return 0;
} Ans: 2356
8)#include <iostream>
#include<stdio.h>
using namespace std;
int func(int n)
{
static int r,m;
if(n)
{
r=n%10;
m=m*100/10+r;
func(n/10);
}
else
return 0;
}
int main()
{
int n;
scanf("%d",&n);
printf("%d",func(n));
return 0;
} Ans: 0
9)#include <iostream>
#include<stdio.h>
using namespace std;
int x;
const int y;
int func(int n)
{
const int y=10*-+1;
return y;
}
int main()
{
int x=NULL;
x=func();
printf("%d",*(&x));
return 0;
} Ans: ce
10)#include <iostream>
#include<stdio.h>
using namespace std;
char* foo(char *p)
{
p+=3;
return(p);
}
int main()
{
char *a,*b;
a="HELLO";
b=foo(a);
printf("%s",b);
return 0;
} Ans:Lo
11)#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
printf("NUmbers Distribution");
printf("%4d\n",4);
printf("%4d\n",45);
printf("%4d\n",456);
printf("%4d\n",4567);
return 0;
} Ans: NUmbers
Distribution 4
45
456
4567
12)#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
int i=100,*j;
j=&i;
i++;
printf("%u, %u, %u",*&i,*&j,&*j);
return 0;
} Ans: , 3212852796, 3212852796
13)#include <iostream>
#include<stdio.h>
using namespace std;
int print_arr(float **p)
{
printf("0 %f 1 %f 2 %f\n", p[0][0],p[0][1],p[0][2])
}
int main()
{
float arr[2][3]={{0,1,2},{3,4,5}};
float**f1_arr;
f1_arr=(float *)arr;
print_arr(f1_arr);
f1_arr++;
print_arr(f1_arr);
return 0;
}Ans: CE
14)#include <iostream>
#include<stdio.h>
using namespace std;
char * m(char *p)
{
p+=2;
return(p++);
}
int main()
{
char *a,*b;
a="POINTER";
b=m(a);
printf("b=%s \n",b);
return 0;
} Ans: =INTER
15)#include <iostream>
using namespace std;
int main() {
// your code goes here
char *a="TOM", *b="Tom";
int i=strcmp(a,b);
int j=stricmp(a,b);
printf("%d %d",i,j);
return 0;
}
Ans:
16)#include <iostream>
#include<stdio.h>
using namespace std;
int main() {
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d%d%d\n",u.ch[0],u.ch[1],u.i);
return 0;
}
Ans: 32515
17)#include <iostream>
#include<stdio.h>
using namespace std;
int x(char *chr)
{
chr=(char *)malloc(10*sizeof(char));
*chr="welcome";
}
int main() {
char *chr="Rajendra";
x(chr);
printf("%s",chr);
return 0;
}
Ans:
18)#include <stdio.h>
void foo(int p[][3])
{
p[0][1]=3;
int i=0,j=0;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
printf("%d",p[i][j]);
}
int main()
{
int arr[2][3]={0};
foo(arr);
return 0;
}
19)#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
fprintf("Action speaks louder than words");
printf("%.ef",2.0);
return 0;
}
20)#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
int a=0,i;
for(i=0;i<a;i+=3)
{
printf("foo");
continue;
printf("bar");
}
return 0;
}
21)#include <iostream>
using namespace std;
#include <stdio.h>
int func(void* a,void *b)
{
if(*a>*b)
printf("%d",*a);
else
printf("%d",*b);
}
int main()
{
int a=10,b=8;
func(&a,&b);
return 0;
}
Ans: ce
22)#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
const int limit=10;
const int*const limitptr=&limit;
int i=27;
limitptr=&i;
printf("%d",*&*limitptr);
return 0;
}
23)#include<stdio.h>
#include<conio.h>
void main()
{
int a=387;
char* ptr;
ptr=(char*)&a;
printf("%d",*ptr);
getch();
}
//-125
24)
#include<stdio.h>
char *fn(char *p)
{
p++;
return(p);
}
void main()
{
char *m,*n;
m="Test";
n=fn(m);
printf("\n%s",n);
return(0);
}
25)
#include<stdio.h>
#define fun(int *i,int *j)(*i=*i**i;*j=*j**j;)
void main()
{
int i=4,j=2;
fun(&i,&j);
printf("%d,%d",i,j);
return(0);
}
26)#include<stdio.h>
#include<conio.h>
void main()
{
int a=320;
char *ptr;
ptr=(char *)&a;
printf("%d",*ptr);
getch();
}
//64
27)
#include<stdio.h>
#include<conio.h>
int mod()
{
int x= x+10;
return x;
}
int chang(x)
{
x=x+1;
return x;
}
void main()
{
int x=10;
x=chang(x);
x++;
printf("%d",x);
x=mod();
printf("%d",x);
getch();
}
//1222
28)#include<stdio.h>
#include<conio.h>
//Recursion
void func1(int*);
void main()
{
int a=7;
clrscr();
func1(&a);
printf("%d\n",a);
getch();
}
void func1(int *b)
{
static int a=1;
if(*b!=0)
{
a=a**b;
*b=*b-1;
func1(b);
}
}
29)
#include<stdio.h>
#include<conio.h>
void main()
{
int k=35,z;
clrscr();
k=func1(k=func1(k=func1(k)));
printf("k=%d",k);
getch();
}
func1(int k)
{
k++;
return(k);
}
//k=38
30)
#include<stdio.h>
#include<conio.h>
void main()
{
char str[7]="Strings";
clrscr();
printf("%s",str);
getch();
}
//StringsA
31)
//error at line 5
#include<stdio.h>
#include<conio.h>
#define Circum(Rver) (3.14*Rvar*Rvar);
void main()
{
float rvar=1.0,c;
cvar=CirCum(rvar);
if(CirCum(rvar)==6.28)
printf("\nGobbledygook");
getch();
}
(32)
#include<stdio.h>
#include<conio.h>
void main()
{
int a=1;
int b=0;
int c=0;
clrscr();
if(a&b==c)
{
printf("abc");
}
else
{
printf("ab");
}
getch();
}
//abc
(33)
#include<stdio.h>
#include<conio.h>
void main()
{
let_us_c()
{
printf("\n C is a simple minded language");
}
printf("\n Others are of course no match");
getch();
}
(34)
#include<stdio.h>
#include<conio.h>
int func(int a,int b)
{
int c=0;
clrscr();
while(b!=0)
{
if(b&01)
c=c+a;
a<<=a;
b>>=1;
}
return c;
}
void main()
{
clrscr();
printf("%d",func(3,5));
getch();
}
//3
(35)
//what will be the output
#include<stdio.h>
#include<conio.h>
void main()
{
int i=100,*j;
clrscr();
j=&i;
i++;
printf("%u,%u,%u",*&i,*&j,&*j);
getch();
}
// 101 address ofj address of j
(36)
#include<stdio.h>
#include<conio.h>
void meth(int a[])
{
int x;
for(x=0;x<3;x++)
{
*a=*a+1;
a++;
}
}
void main()
{
static int a[4]={1,2,3,4};
int b;
clrscr();
meth(a);
for(b=3;b>0;b--)
printf("%d",a[b]);
getch();
}
//443
(37)
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5]={1,2,3,4,5};
// clrscr();
int *p=(int*)(&a+1);
clrscr();
printf("%d%d", *(a+1),*(p-1));
getch();
}
//25
(38)
#include<stdio.h>
#include<conio.h>
struct a
{
int a[5]={1,2,3,4,5};
};
void main()
{
int i;
struct a p={5,4,3,2,1},q;
q=p;
for(i=0;i<5;i++)
{
printf("%d",q.a[i]);
}
getch();
}
//error
(39)
#include<stdio.h>
#include<conio.h>
int power(int **);
void main()
{
int a=5,*aa;
aa=&a;
clrscr();
a=power(&aa);
printf("%d\n",a);
getch();
}
int power(int **p)
{
int b;
b=**p***p;
return b;
}
//25
(40)
#include<stdio.h>
#include<conio.h>
void main()
{
char *a="Raj";
char *b;
clrscr();
b=(char *)malloc(20);
while(*a++==*b++);
printf("%s",*b);
getch();
}
//null
(41)
#include<stdio.h>
#include<conio.h>
void main()
{
char *s[]={"fortran","ajax","c++","linux","js","c#"};
int n;
char *p;
p=s[3];
s[3]=s[4];
s[4]=p;
clrscr();
for(n=0;n<=5;n++)
printf("%s,",s[n]);
getch();
}
//fortran,ajax,c++,js,linux,c#
(42)
#include<stdio.h>
#include<conio.h>
void main()
{
int a[][2]={1,2,3,4,5,6};
clrscr();
printf("%d",**(a+1));
getch();
}
//3
(43)
#include<stdio.h>
#include<conio.h>
void main(int argc,char *argv[])
{
char s[]={'1','2','3','4','5','6'};
char *p,*s1,*s2;
clrscr();
p=&s[3];
s1=p;
s2=s;
printf("%d",++*p+++*s2-32);
getch();
}
//70
(44)
#include<stdio.h>
#include<conio.h>
int func(int,int);
void main()
{
int c;
clrscr();
c=func(15,35);
printf("c=%d\n",c);
getch();
}
int func(int i,int j)
{
int *p,*q;
p=&i;
q=&j;
i>=45?return(*p):return(*q);
}
//error
(45)
#include<stdio.h>
#include<conio.h>
void main()
{
char *c=NULL;
int *i=NULL;
clrscr();
c="AA";
*i=100;
*(i+1)=200;
printf("%c,%d,%d\n",*c,*i,i[1]);
getch();
}
//a 100,200
(46)
#include<stdio.h>
#include<conio.h>
int fun(void *a,void *b)
{
if(*a>*b)
printf("%d",*a);
else
printf("%d",*b);
}
void main()
{
int a=10,b=8;
getch();
func(&a,&b);
getch();
}
(47)
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,*j;
clrscr();
void *k;
j=k=&a;
j++;
k++;
printf("%u %u",j,k);
getch();
}
(48)
#include<stdio.h>
#include<conio.h>
int func1(int x)
{
return x-1;
}
int func2(int y)
{
return y-1;
}
void main()
{
int i=0,ret=0;
f[0]=func1;f[1]=func2;
for(i=10;i<12;i++)
{
ret=f[i-10](i);
printf("%d ",ret);
}
getch();
}
//error
(49)
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while(i<=5)
{
printf("%d",i);
if(i>2)
goto here;
i++;
}
here:
printf("hello world");
getch();
}
//123hello world
(50)
#include<stdio.h>
#include<conio.h>
void main()
{
int a=320;
char *ptr;
ptr=(char *)&a;
printf("%d",*ptr);
getch();
}
//64
(51)
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
static char arr[]="Hello Brother";
clrscr();
printf("%d\n",*(arr+strlen(arr)));
getch();
}
//0
(52)
#include<stdio.h>
#include<conio.h>
int mod()
{
int x= x+10;
return x;
}
int chang(x)
{
x=x+1;
return x;
}
void main()
{
int x=10;
x=chang(x);
x++;
printf("%d",x);
x=mod();
printf("%d",x);
getch();
}
//1222
(53)
#include<stdio.h>
#include<conio.h>
void main()
{
int z[]={1,2,3,4,4,1,1,1,1,10};
int x=0,y=0;
clrscr();
for(x=1;x<10;x-=-x-1)
{
y+=z(x);
}
printf("%d\n %d",x,y);
getch();
}
//15,7
(54)
#include<stdio.h>
#include<conio.h>
void func(int **p)
{
int b=1;
*p=&b;
printf("%d ",**p);
}
void main()
{
int a=2,*p=&a;
clrscr();
func(&p);
printf("%d",*p);
getch();
}
//1 1
(55)
#include<stdio.h>
#include<conio.h>
void main()
{
extern char *s[3];
typedef char *(*p)[3];
static p p1=&s,p2=&s,p3=&s;
char*(*a[3]))[3]={&p1,&p2,&p3};
char*(*(*p)[3]) )[3]=&a
printf("%s",(***p[0][1]);
}
extern char *s[3]={"one","two","Three" };
Back
No comments:
Post a Comment