0% found this document useful (0 votes)
3 views

Cpaper2

The document contains a series of C programming questions and code snippets that cover various concepts such as pointers, arrays, structures, and file handling. Each question includes a main function and specific tasks or outputs to be achieved, testing the reader's understanding of C programming. The document serves as a resource for learning and practicing C programming skills.

Uploaded by

pankajpushpatode
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Cpaper2

The document contains a series of C programming questions and code snippets that cover various concepts such as pointers, arrays, structures, and file handling. Each question includes a main function and specific tasks or outputs to be achieved, testing the reader's understanding of C programming. The document serves as a resource for learning and practicing C programming skills.

Uploaded by

pankajpushpatode
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

JobSeekerSolution.wordpress.

com

JobSeeker SOLUTIONS

SET-B
Note:-
The program output may depend on the information based on this assumptions (for
example sizeof(int) == 2 may be assumed).

Q1) main()
{
show();
}
void show()
{
printf("I'm the greatest");
}

Q2) main( )
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(“%u %u %u %d \n”,a,*a,**a,***a);
printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1);
}

Q3) main( )
{
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++)
{
printf(“%d” ,*a);
a++;
}
p = a;
for(j=0; j<5; j++)
{
printf(“%d ” ,*p);
p++;
}
}

Q4) main( )
{
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;

Page 1
JobSeekerSolution.wordpress.com

ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
}

Q5) main( )
{
char *q;
int j;
for (j=0; j<3; j++) scanf(“%s” ,(q+j));
for (j=0; j<3; j++) printf(“%c” ,*(q+j));
for (j=0; j<3; j++) printf(“%s” ,(q+j));
}

Q6) main( )
{
void *vp;
char ch = ‘g’, *cp = “goofy”;
int j = 20;
vp = &ch;
printf(“%c”, *(char *)vp);
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
printf(“%s”,(char *)vp + 3);
}

Q7) main ( )
{
static char *s[ ] = {“black”, “white”, “yellow”, “violet”};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf(“%s”,*--*++p + 3);
}

Q8) main()
{
int i, n;
char *x = “girl”;
n = strlen(x);

Page 2
JobSeekerSolution.wordpress.com

*x = x[n];
for(i=0; i<n; ++i)
{
printf(“%s\n”,x);
x++;
}
}

Q9) int i,j;


for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}

Q10) main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}

Q11) What are the files which are automatically opened when a C file is executed?

Q12) what will be the position of the file marker?


a: fseek(ptr,0,SEEK_SET);
b: fseek(ptr,0,SEEK_CUR);

Q13) main()
{
char name[10],s[12];
scanf(" \"%[^\"]\"",s);
}
How scanf will execute?

Q14) What is the problem with the following code segment?


while ((fgets(receiving array,50,file_ptr)) != EOF);

Q15) main()
{
main();
}

Page 3
JobSeekerSolution.wordpress.com

Q16) main()
{
char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
}

Q17) main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}

Q18) main()
{
char not;
not=!2;
printf("%d",not);
}

Q19) #define FALSE -1


#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}

Q20) main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}

Q21) main()
{
int y;
scanf("%d",&y); // input given is 2000

Page 4
JobSeekerSolution.wordpress.com

if( (y%4==0 && y%100 != 0) || y%100 == 0 )


printf("%d is a leap year");
else
printf("%d is not a leap year");
}

Q22) #define max 5


#define int arr1[max]
main()
{
typedef char arr2[max];
arr1 list={0,1,2,3,4};
arr2 name="name";
printf("%d %s",list[0],name);
}

Q23) int i=10;


main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}

Q24) main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}

Q25) main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);

Page 5
JobSeekerSolution.wordpress.com

Q26) #include<stdio.h>
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}

Q27) #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d",*p,*q);
}

Q28) #include<stdio.h>
main()
{
register i=5;
char j[]= "hello";
printf("%s %d",j,i);
}

Q29) main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}

Q30) struct aaa{


struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi,jkl;
int x=100;
abc.i=0;abc.prev=&jkl;

Page 6
JobSeekerSolution.wordpress.com

abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
}

Q31) struct point


{
int x;
int y;
};
struct point origin,*pp;
main()
{
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}

Q32) main()
{
int i=_l_abc(10);
printf("%d\n",--i);
}

int _l_abc(int i)
{
return(i++);
}

Q33) main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
}

Page 7
JobSeekerSolution.wordpress.com

Q34) main()
{
char c=' ',x,convert(z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c);
printf("%c",x);
}
convert(z)
{
return z-32;
}

Q35) main(int argc, char **argv)


{
printf("enter the character");
getchar();
sum(argv[1],argv[2]);
}
sum(num1,num2)
int num1,num2;
{
return num1+num2;
}

Q36) # include <stdio.h>


int one_d[]={1,2,3};
main()
{
int *ptr;
ptr=one_d;
ptr+=3;
printf("%d",*ptr);
}

Q37) # include<stdio.h>
aaa() {
printf("hi");
}
bbb(){
printf("hello");
}
ccc(){
printf("bye");
}
main()
{

Page 8
JobSeekerSolution.wordpress.com

int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}

Q38) #include<stdio.h>
main()
{
FILE *ptr;
char i;
ptr=fopen("zzz.c","r");
while((i=fgetch(ptr))!=EOF)
printf("%c",i);
}

Q39) main()
{
int i =0;j=0;
if(i && j++)
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}

Q40) main()
{
int i;
i = abc();
printf("%d",i);
}
abc()
{
_AX = 1000;
}

Q41) int i;
main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--",t--);
}
// If the inputs are 0,1,2,3 find the o/p

Page 9
JobSeekerSolution.wordpress.com

Q42) main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello");
}

Q43) main(){
unsigned int i;
for(i=1;i>-2;i--)
printf("c aptitude");
}

Page 10

You might also like