Find the output of following c program
1. #include<stdio.h>
int main()
{
int
i,size=5,arr[size];
for(i=0;i<size;i++)
printf("%d
",arr[i]);
return 0;
}
2. #include<stdio.h>
int main()
{
int
i,size=5,arr[size]={1,2,3,4,5};
for(i=0;i<size;i++)
printf("%d
",arr[i]);
return
0;
}
3. #include<stdio.h>
int main()
{
int
i;
int
arr[4]={1,2,3};
for(i=0;i<4;i++)
printf("%d
",arr[i]);
return
0;
}
4. #include<stdio.h>
int main()
{
int arr[4]={2,4,6,8},i=4,j;
while(i)
{
j=arr[i]+i;
i--;
}
printf("j=%d\n",j);
return 0;
}
5. #include<stdio.h>
int main()
{
int
i=0,sum=0,arr[4]={4,2,0,6};
while(arr[i])
{
sum=sum+arr[i] ;
i++;
}
printf("sum=%d",sum);
return
0;
}
6. #include<stdio.h>
int main()
{
int
i=0,sum=0,arr[4]={4,2,0,6};
for(;i;i++)
sum=sum+arr[i];
printf("sum=%d",sum);
return 0;
}
7. #include<stdio.h>
int main()
{
int
i,arr[8]={1,2,3,4,5,6,7,8} ;
for(i=7;i>=0;i--)
printf
("%d\t",--arr[--i]);
return 0;
}
8. #include<stdio.h>
int main()
{
int
a[3]={2,5,-4};
int
i=0;
for(;i<3;i++)
printf("%d
", i[a]--);
return
0;
}
9. #include<stdio.h>
void func(int
arr[]);
int main()
{
int
arr[5]={1,2,3,4,5};
func(arr);
return 0;
}
void func(int
arr[])
{
int
i=5, sum=0;
while(i>2)
sum=sum+arr[--i]
;
printf("sum=%d\n`",sum);
}
10. #include<stdio.h>
int main()
{
int
x[10],y[3][4];
char z[2][3][5];
printf("%u
\t %u \t %u\n",sizeof(x),sizeof(y),sizeof(z));
return 0;
}
11. #include<stdio.h>
void swapvar(int
a,int b);
int main()
{
int a=4,b=6;
swapvar(a,b) ;
printf("a=%d,b=%d\n",a,b)
;
return 0;
}
void swapvar(int
a,int b)
{
int temp;
temp=a,a=b,b=temp;
}
12. #include<stdio.h>
int main()
{
int
arr[5]={'a','e','i','o','u'};
int
i=0;
for(;i<5;i++)
printf("%c
",arr[i]);
return
0;
}
13. #include<stdio.h>
void swaparr(int
arr1[],int arr2[]);
int main()
{
int
arr1[2]={1,2};
int
arr2[2]={3,4};
swaparr(arr1,arr2);
printf
("arr1[0]=%d,arr1[1]=%d\n",arr1[0],arr1[1]);
printf("arr2[0]=%d,arr2[1]=%d",arr2[0],arr2[1]);
return
0;
}
void swaparr(int
arr1[],int arr2[] )
{
int i,temp;
for(i=0;i<2;i++)
temp=arr1
[i],arr1[i]=arr2[i],arr2[i]=temp;
}
14. #include<stdio.h>
int main()
{
int
i,j,arr[3][4]={{1,2,3,4},{5,6,7,8},{9,10,1l,12}};
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
printf("%3d",arr[j][i]);
printf
("\n");
}
return 0;
}
15. #include<stdio.h>
void fun(int[]);
int main()
{
int arr[3]={2,4,6};
fun(arr);
printf("%d ",arr[1]);
return 0;
}
void fun(int
arr[])
{
arr[1]=5;
}
16. #include<stdio.h>
void fun(int[]);
int main()
{
int arr[3]={2,4,6},i;
for(i=0;i<3;i++)
printf("%d ",++arr[i]);
return 0;
}
17. #include<stdio.h>
void fun(int[]);
int main()
{
int
arr[]={1};
arr++
printf("%d
",arr);
return
0;
}
ANSWER
1.
gv gv gv gv gv
2.
Compilation error
3.
1 2 3 0
4.
J=5
5.
Sum=6
6.
Sum=0
7.
6 4 2 0
8.
2 5 -4
9.
Sum=12
10.
40 48
30
11.
a=4,b=6
12.
a e i o u
13.
arr1[0]=3,arr1[1]=4
arr2[0]=1,arr2[1]=2
14.
1
5 9
2 6 10
3 7 11
4 8 12
15.
5
16.
3 5 7
17.
compilation error
No comments:
Post a Comment
For any doubt or suggestion you can write here