Question

( C prog) write an output for the following code fragment int a[]= {1, 2, 3,...

( C prog) write an output for the following code fragment int a[]= {1, 2, 3, 4, 5, 6}: int *ip; int i; ip=a; ip +=3; *ip= *ip * 3; for (i=0; i <6; ++i) printf("%d," a[i]);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

Here i have re-written the C program as per the requirement. And also commented out the code for your better undertanding. below i have attached the code and the corresponding output.

NOTE:1 Please note that the below programs have been tested on ubuntu 14.04 system and compiled under gcc compiler. This code will also work on other IDE's.

--------------------------------------------------------------------------------------------------------------------------------------

Program.. -------------------------------------------------------------------------------------------------------------------------------------

//Header file declaration

#include<stdio.h>

#include<stdlib.h>

int main()

{

//this is the array initialization

int a[]= {1, 2, 3, 4, 5, 6};

//pointer and variable declaration

int *ip;

int i;

//assining pointer to tha array

ip=a;

//adding a value to pointer variable

ip +=3;

//multiplying pointer by three

*ip= *ip * 3;

//loop to print updated array values

for(i=0; i <6; ++i)

printf("%d ", a[i]);

printf("\n");

return 0;

}//end of the program


----------------------------------------------------------------------------------------------------------------------------------------

here i have attached the output of the program as a screen shot...

Output:

-------------------------------------------------------------------------------------------------------------------------------------

nirmalsharmaubuntu:-/HomeworkLib solutions/27_07_2017$ gcc output.c nirmalsharma@ubuntu:-/HomeworkLib solutions/27_07_20175 -/a.out 1 2 3

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Kindly Check and Verify Thanks...!!!

Add a comment
Know the answer?
Add Answer to:
( C prog) write an output for the following code fragment int a[]= {1, 2, 3,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT