C programming language List the results that will be produce

C programming language

List the results that will be produced if the following program were to be executed. You can indicate the results on the right hand column. #include int main() {int i; int *p[3]; int p1[]={l, 2, 3), P2[]={9, 3, 4}, P3[]={2}; char *s[2] = {\"Test 1\", \"First test\"}; p[0]=p1; p[1] =p2; p[2]=p3; printf(\" 1st Print: \ \"); for (i=0; i

Solution

The output is explained in the code as comments:

#include <stdio.h>
int main()
{
int i;
int *p[3];
int p1[] = {1, 2, 3}, p2[] = {9, 3, 4}, p3[] = {2};
  
char *s[2] = {\"Test 1\", \"First test\"};
  
p[0] = p1; //p[0] points to first element in the array p1.
p[1] = p2; //p[1] points to first element in the array p2.  
p[2] = p3; //p[2] points to first element in the array p3.
  
printf(\" 1st Print:\ \");
for(i = 0; i < 3; i++) //This loop runs for 3 values 0, 1, and 2.
printf(\"%d \", p[i][0]); //p[0][0] will print 1, p[1][0] will print 9, p[2][0] will print 2.
  
printf(\"\ \ 2nd Print:\ \");
for(i = 0; i < 3; i++) //This loop runs for 3 values 0, 1, and 2.
printf(\"%d \", p[0][i]); //p[0][0] will print 1, p[0][1] will print 2, p[0][2] will print 3.

printf(\"\ \ 3rd Print:\ \");
for(i = 0; i < 7; i++) //This loop runs for 7 values, 0, 1, 2, 3, 4, 5, and 6.
printf(\"%p \", *p); //This will print the address of the array p1.
  
printf(\"\ \ 4th Print:\ \ \");
for(i = 0; i < 3; i++)   //This loop runs for 3 values 0, 1, and 2.
printf(\"%d \", *p[i]);   //*p[0] will print 1, *p[1] will print 9, *p[2] will print 2.
  
printf(\"\ \ 5th Print:\ \");
printf(\"\ %s and %s \", s[0], s[1]); //This will print 2 strings. Test1 and First test
  
printf(\"\ \ 6th Print:\ \");
printf(\"%c in s1 and %c in s2\ \", s[0][0], s[1][0]); //This will print 2 characters. T in s1 and F in s2
  
return 0;
}

And the output is:

1st Print:

1 9 2

2nd Print:

1 2 3

3rd Print:

0x7fff50c4a704 0x7fff50c4a704 0x7fff50c4a704 0x7fff50c4a704 0x7fff50c4a704 0x7fff50c4a704 0x7fff50c4a704

4th Print:

1 9 2

5th Print:

Test 1 and First test

6th Print:

T in s1 and F in s2

C programming language List the results that will be produced if the following program were to be executed. You can indicate the results on the right hand colum
C programming language List the results that will be produced if the following program were to be executed. You can indicate the results on the right hand colum

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site