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
  • Write the output from the following code fragment: for (int i = 1; I < 7;...

    Write the output from the following code fragment: for (int i = 1; I < 7; ++i) { switch (i) { case 1: printf ("\n%d Banana", i); case 2: printf ("\n%d Kumquat", i);

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2,...

    QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3};         int *p = a;         int **r = &p;         printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points    QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4};         int *p;         p = arr + 3;         *p = 5;         printf("%d\n", arr[3]); A....

  • What is the output of the following fragment? please explain. C language int i = 1;...

    What is the output of the following fragment? please explain. C language int i = 1; int j = 1; while (i < 5) { i++; j = j * 2; } printf(“%d”, j); (a) 4 (b) 8 (c) 16 (d) 32

  • What is the output of the following code fragment? int i = 1; while( i <=...

    What is the output of the following code fragment? int i = 1; while( i <= 5 ) if(i == 2 || i == 4) System.out.println(i + ":" + " is an even index) System.out.println("i: " + i); i++;

  • QUESTION 6 What is the output of following C code? struct numbers     {         int x...

    QUESTION 6 What is the output of following C code? struct numbers     {         int x = 2;         int y = 3;     } int main() {   struct numbers nums;         nums.x = 110;         nums.y = 100;         printf("%d\n%d", nums.x, nums.y);         return 0; } A. Compile-time Error B. 110 100 C. 2 3 D. Run-time Error 2 points    QUESTION 7 What is the output of following C code? typedef struct student {         char *stud; }s1; int main() {   s1 s;         s.stud...

  • Given the following Java code fragment, what is output? int a, b; String c, d, e;...

    Given the following Java code fragment, what is output? int a, b; String c, d, e; String x = new String(“I LOVE”); String y = “java!”; a = x.length( ); System.out.println(“1) “ + a); b = y.length( ); System.out.println(“2) “ + b); c = y.toUpperCase( ); System.out.println(“3) “ + c); d = x.toLowerCase( ); System.out.println(“4) “ + d); e = x.concat(y); System.out.println(“5) “ + e);

  • Given the following code in C, what is the output of this program? (10 Points) int...

    Given the following code in C, what is the output of this program? (10 Points) int mainO f 5. int i=10; for(int j-l;j-3;j++) int i=5 printf("i=%dn', i); printf("f%d\n", i); return 0;

  • QUESTION Z What is the output of the following code: int list[] = {1, 2, 3,...

    QUESTION Z What is the output of the following code: int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < 6; i++) list[i] = list[i - 1]; for (int i = 0; i < 6; i++) cout << list[i] << ""; 0 1 2 3 4 5 6 0 2345 61 0 111111 0 234 566

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

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