C-language 56 programming Questions
1.
#include<stdio.h>
void main()
{
int arr[];
arr[1]=10;
printf("%d",arr[0]);
}
2.
#include<stdio.h>
void main()
{
int arr[2]={10,20,30,40};
printf("%d",*(arr+2));
}
3.
#include<stdio.h>
void main()
{
int arr[2]={10,20};
arr[2]=30;
arr[3]3=40;
printf("%d",*(arr+3));
}
4.
#include<stdio.h>
void main()
{
int arr[2]={10,20};
*arr=30;
*(arr+1)=40;
printf("%d%d",arr[0],1[arr]);
}
5.
#include<stdio.h>
void main()
{
int a=1;
void xyz(int,int);
xyz(++a,a++);
xyz(a++,++a);
printf("\n%d",a);
}
void xyz(int x,int y)
{
printf("\n%d%d",x,y);
}
6.
#include<stdio.h>
void abc()
{
++a;
}
void main()
{
int a=1;
abc();
printf("\n %d",a);
}
7.
void display(int a)
{
printf("\n %d",a);
if(--a)
display(a);
printf("\n%d",a);
}
void main()
{
display(4);
}
8.
void xyz(int x)
{
printf("\n%d",x);
if(x)
xyz(x-1);
printf("\n%d",x);
}
void abc(int a)
{
printf("\n%d",a);
xyz(a);
if(a)
abc(a-1);
printf("\n%d",a);
}
void main()
{
abc(2);
}
9.
#include<stdio.h>
void main()
{
static int a=1;
printf("\n%d",++a);
if(a<=3)
main();
printf("\n%d",a);
}
10.
#include<stdio.h>
void main()
{
int a=32767,b;
char *ptr;
ptr=&a;
b=*ptr;
printf("\n%d%d",a,b);
}
11.
#include<stdio.h>
void main()
{
int a=10;
int *p=&a;
int **pp=&p;
++*p;
++**pp;
a*=a-2;
printf("\n%d",*a);
}
12.
void change(int p1,int *p2)
{
++p1;
++*p2;
}
void main()
{
int x=10,y=20;
change(x,&y);
printf("\n%d%d",x,y);
}
13.
#include<stdio.h>
void main()
{
int a[]=[7,18,29};
int *p;
p=a;
++p;
printf("%d%d%d",p[-1],p[0],p[1]);
}
14.
void xyz(int *ptr)
{
++*ptr;
if(*ptr<=10)
xyz(++ptr);
++*ptr;
}
void main()
{
int arr[]={2,4,8,14,16};
int i;
xyz(arr+1);
for(i=0;i<5;i++)
printf("%d",arr[i]);
}
15.
#include<stdio.h>
void main()
{
int arr[4][8]={10,20,30};
printf("\n%d",sizeof(arr));
printf("\n%d",sizeof(arr[1]));
printf("\n%d",sizeof(arr[1][0]);
}
16.
#include<stdio.h>
void main()
{
int arr[4][8]={10,20,30};
printf("\n%d",&arr[3][4]-&arr[1][2]);
}
17.
#include<stdio.h>
void main()
{
int arr[3][]={
{7,8,9},
{3,13},
{10,20,30}
};
printf("\n%d",arr[1][1]);
}
18.
#include<stdio.h>
void main()
{
int arr[][4]={
{7,8,9},
{3,13},
{10,20,30}
};
printf("\n%d",arr[1][1]);
}
19.
#include<stdio.h>
void main()
{
int arr[5]={10,20};
printf("\n%d%d",1[arr],arr[0]);
}
20.
#include<stdio.h>
void main()
{
int arr1[5]={10,20};
int arr2[5];
printf("\n%d%d",arr1[3],arr2[3]);
}
21.
#include<stdio.h>
void main()
{
int a[2];
int i;
for(i=0;i<10;i++)
a[i]=i*i;
printf("%d%d",a[3],a[4]);
}
22.
#include<stdio.h>
void main()
{
int a[5]={10,20,30,40,50};
int b[5]={3,13};
b=a;
printf("%d",b[1]);
}
23.
#include<stdio.h>
void main()
{
int a[5]={6,16,26};
++*a;
++*(a+1);
++a[1];
printf("%d%d",a[0],a[1]);
}
24.
#include<stdio.h>
void main()
{
int a[5]={10,20,30,40,50};
int *ptr;
ptr=a+1;
printf("%d%d%d",++*ptr,*ptr++,*++ptr);
}
25.
#include<stdio.h>
void main()
{
char str[5]={'a','b','c','d'};
printf("%s",str);
}
26.
#include<stdio.h>
void main()
{
char str[]="abcdefghxyz";
printf("\n%s",str);
printf("\n%s",str+4);
printf("\n%s",str+8);
}
27.
#include<stdio.h>
void main()
{
char str[]="Naresh IT";
str[1]++;
str[2]=100;
puts(str);
}
28.
#include<stdio.h>
void main()
{
char str[]="abcdef";
str[3]=0;
puts(str);
}
29.
#include<stdio.h>
void main()
{
char str1[]="hello";
char str2[]="abc";
str1=str2;
puts(str1);
}
30.
void display(char *str)
{
puts(str)
if(*str)
display(str+1);
puts(str);
}
void main()
{
char st[]="abc";
display(st);
}
31.
#include<stdio.h>
void main()
{
char str="abcdef";
++str;
++*str;
puts(str);
}
32.
void main()
{
char str[]="Balu";
printf("%d%d",sizeof(str),strlen(str));
}
33.
#include<stdio.h>
void main()
{
char str1[20]= "hello Naresh IT";
char str2[20]="hello Balu";
strcpy(str1+6,str2+6);
puts(str1);
puts(str2);
}
34.
char *change(char *ptr)
{
++*ptr;
++[tr;
ptr+=2;
*ptr+=2;
return ptr-2;
}
void main()
{
char name[]="hello rahul";
puts(change(name));
puts(name);
}
35.
#include<stdio.h>
void main()
{
char str[40]="welcome";
char *p;
p=str+7;
strcpy(p,"balu");
puts(p);
puts(str);
}
36.
#include<stdio.h>
void main()
{
char s1[40]="abcdef";
char *s2="Naresh IT";
char *s3="Balu";
s3=s2+2;
s2=s1+2;
++*s2;
++*s3;
puts(s1);
puts(s2);
puts(s3);
}
37.
#include<stdio.h>
void main()
{
char str[40]="abc789101112";
strrev(str+3);
puts(str);
}
38.
#include<stdio.h>
void main()
{
char s1[40]="abcdf";
char s2[]="xyz";
strcat(s1+2,s2+1);
puts(s1);
puts(s2);
}
39.
void dump(char *p1,char *p2)
{
while(*p1++=*p2++);
}
void main()
{
char str1[]="hello Naresh IT";
char str2[]="Balu";
dump(str1,str2);
puts(str1);
puts(str2);
}
40.
#include<stdio.h>
void main()
{
char s[4][40]={"abc","123","xyz"};
char *p[4]={"pascal","cobol"};
printf("\n%d",sizeof(s));
printf("\n%d",sizeof(p));
}
41.
#include<stdio.h>
void main()
{
char str[2]="hello";
puts(str);
}
42.
#include<stdio.h>
void main()
{
char str[2];
strcpy(str,"hello");
puts(str);
}
43.
#define cube(x) (x*x*x)
void main()
{
int a;
a=cube(2);
printf("%d",a)'
a=cube(2+3);
printf("%d",a);
}
44.
#define A 10
void main()
{
int x;
x=++A;
printf("%d%d",x,A);
}
45.
enum{a,b,c=10,d};
void main()
{
printf("\n %d%d%d",a,b,c,d);
}
46.
struct a
{
int x,y,z;
}a1;
void main()
{
printf("%d",sizeof(a1));
}
47.
struct B
{
struct
{
int x;
int y;
int z;
}obj1,obj2;
int a;
int b;
}b1;
void main()
{
printf("%d",sizeof(b1));
}
48.
for above struct B variable b1 how to interact with member x...?
49.
union a
{
int a;
char c;
}obj;
void main()
{
obj.a=511;
printf("%d%d",obj.a,obj.c);
obj.c=1;
printf("%d%d",obj.a,obj.c);
}
50.
typedef struct
{
int d;
char na[30];
int sal;
}emp;
void main()
{
emp e1;
emp *ptr;
ptr=&e1;
...
...
}
in the above object e1 need to change name to "Naresh IT" which are valid
1.e1.na="Naresh IT";
2.atrcpy(e1.na,"Naresh IT");
3.ptr->na="Naresh IT";
4.strcpy(ptr->na,"Naresh IT");
51.
for the same object e1 need to change id to 1 which are valid.
1.e1.id=1;
2.e1->id=1;
3.ptr.id=1;
4.*ptr.id=1;
5.ptr->id=1;
52.
fopen required how many arguments?
53.
what are the differences between malloc and calloc
1. malloc has 2 args calloc has 1 args
2.malloc all bytes are garbage.calloc all bytes are zeros
3.calloc all bytes are garbage.malloc all bits are zeros.
4.malloc has 1 args and calloc has 2 args.
54.
if malloc fails what it returns?
55.
what is the default value of argc--,argv[0]--?
56.
what is __argc,__argv and where it is defined?
Comments
Post a Comment