4 using c language please explain What is the output of foll

?4. using c language, please explain

What is the output of following program #include void foo(int[]); int main() {int ary[4] = {1, 2, 3, 4}; foo(ary); printf(\"%d\", ary[0]);} void foo(int p[4]) {int i = 10; p = &i; printf(\"%d, *p); printf(\"%d \", p[0]);} No answer text proved. 1 1 1 10 10 1 10 1 1

Solution


#include <stdio.h>

void foo(int[]);

int main(){

   int ary[4] = {1,2,3,4};
   foo(ary);

   printf(\"%d \",ary[0]); // here at first location, we have 1

   return 0;
}

void foo(int p[4]){

   int i = 10;

   // p is a pointer, here we are storing address of \'i\' in p
   p = &i;

   printf(\"%d \",*p ); // p has address of i, so output: 10
   printf(\"%d \",p[0] ); // p and p[0] denotes first element stored in pointer p
                       // output: 10
}

Output: 10 10 1

?4. using c language, please explain What is the output of following program #include void foo(int[]); int main() {int ary[4] = {1, 2, 3, 4}; foo(ary); printf(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site