Question

int i,sum=0;   int array[8]={//You decide this};   int *a,*b,*c;   a = array;   b = &array[3];   c =...

int i,sum=0;

  int array[8]={//You decide this};

  int *a,*b,*c;

  a = array;

  b = &array[3];

  c = &array[5];

  c[-1] = 2;

  array[1] = b[1]-1;

  *(c+1) = (b[-1]=5) + 2;

  sum += *(a+2) + *(b+2) + *(c+2);

  printf("%d %d %d %d\n",

sum, array[b-a], array[c-a], *a-*b);

array[8]={ ?? };

what is array[8]?

Homework Answers

Answer #1

Answer: Array is [1, 1, 5, 4, 2, 6, 7, 8 ]

Note1**: (if initial array ={1,2,3,4,5,6,7,8})

Note2: Please refer the below code and comments for the detailed explanation

#include <stdio.h>

int main(void) {
        int i,sum=0;

  int array[8]={1,2,3,4,5,6,7,8};

  int *a,*b,*c;

  a = array; // a will now point to base address of array

  b = &array[3]; // b will now point to 4th element of array 

  c = &array[5]; // c will now point to 6th element of array 

  c[-1] = 2;  
    // c point to 6th element of array. 
    //Hence, 5th element of array will be updated to 2
    //array={1,2,3,4,2,6,7,8}
    
  array[1] = b[1]-1;
    // array[1]=2-1=1 (as b[1]=2)
    //array={1,1,3,4,2,6,7,8}

  *(c+1) = (b[-1]=5) + 2;
    // b points to 4th element of array. hence3rd element of array will be 5 (as b[-1]=5)
    // c point to 6th element of array
    // Here c+1 will point to 7th element of array
    // Value of 7th element will be updated to 7;
    // array={1,1,5,4,2,6,7,8}
  sum += *(a+2) + *(b+2) + *(c+2);
    //sum= 5 + 6+ 8 = 19
  printf("%d %d %d %d\n",sum, array[b-a], array[c-a], *a-*b); 
  array[8] = 99 // in array "array", 8th index is outside the defined boundary. Hence this assignment will be ignored.

        return 0;
}




Note3:Refer Screenshot for code indentation

The Output of the above code upon its execution will be ->

19 4 6 -3

Note4: Array[8] is an position which is outside the defined range of array(since array is defined for 8 elements of int type having position 0 to 7). Hence array[8]={some value} will not be reflected in array.

Know the answer?
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
Similar Questions
1. public int add100(int[] array) { if (array.length < 100) { return 0; } int sum...
1. public int add100(int[] array) { if (array.length < 100) { return 0; } int sum = 0; for (int i = 0; i < 100; i++) { sum += array[i]; } return sum; } 2. int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { sum++; sum++; } } for (int i = 0; i < n; i += 2) { sum++; } 3. nt...
Consider the following array: int[] a = { 3, 5, 2, 2, 4, 7, 0, 8,...
Consider the following array: int[] a = { 3, 5, 2, 2, 4, 7, 0, 8, 9, 4 }; What are the contents of the array a after the following loops complete? (show how you arrive at the answer) a) for (int i = 1; i < 10; i++) { a[i] = a[i - 1]; b) for (int i = 9; i > 0; i--) { a[i] = a[i - 1]; }
#include <stdio.h> extern unsigned long long sum(unsigned int *array, size_t n); int main(void) { unsigned int...
#include <stdio.h> extern unsigned long long sum(unsigned int *array, size_t n); int main(void) { unsigned int array[] = { 1, 1, 1, 3 }; unsigned long long r = sum(array, sizeof(array) / sizeof(*array)); printf("Result is: %llu (%s)\n", r, r == 6 ? "correct" : "incorrect"); return 0; } Complete the code for the line that calls the sum function. Write the sum function.
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i];...
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i]; } return (double)sum/n; } Rewrite the function to eliminate the array subscripting (a[i]), using pointer arithmatic instead. Write a program that reads a line of input and checks if it is a palindrome (ignoring spaces) Write a program that takes the name of a file as a command line argument, and prints the contents of the file (similar to the linux 'cat' program). Write...
A programmer that you work with, Peter, is a jerk. He is responsible for an array...
A programmer that you work with, Peter, is a jerk. He is responsible for an array that is a key part of an important program and he maintains a sum of the array value.He won't give you access to this array; however, your boss has told you that you need to get input from the user and then place it into the array.Each evening Peter will scan the code and remove any illegal references to his array. Using pointers, access...
#include <stdio.h> #include <stdlib.h> int main () { int k; int aux; int size = 8;...
#include <stdio.h> #include <stdlib.h> int main () { int k; int aux; int size = 8; int x[8] = {2, 3, 5, 7, 11, 13, 17, 19}; scanf("%d",&k); aux = x[k]; for (int i = k; i < size - 1; i++) x[i] = x[ i + 1]; x[ size - 1] = aux;   for (int i = 0; i < size; i++) printf("%d ", x[i]); } change this program to Write a program to remove an element from an...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8 13 21 34 55 ....... and also need add code complexity time if you want! here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[ n + 1 ]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for ( i = 2; i < n; i++ ) { fib[ i ] = fib[ i -...
int main() { int i, j, sum = 0; for(i=0;i<3;i++) { for(j=0;j<4;j++) { if(j > 2)...
int main() { int i, j, sum = 0; for(i=0;i<3;i++) { for(j=0;j<4;j++) { if(j > 2) break; sum++; } } } What is value of sum, explain.
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an executable with gcc -Wall -DUNIT_TESTS=1 array-utils5A.c The definitions for is_reverse_sorted and all_different are both defective. Rewrite the definitions so that they are correct. The definition for is_alternating is missing. Write a correct definition for that function, and add unit tests for it, using the unit tests for is_reverse_sorted and all_different as models. Please explain the logic errors present in in the definition of is_reverse_sorted...
Consider the following variable definitions: char a, *b, *c; int d[2], *e; int i, *j; How...
Consider the following variable definitions: char a, *b, *c; int d[2], *e; int i, *j; How many total bytes does this code allocate for variables?  Assume a 32-bit representation for integer and pointer values. a     sizeof(char) b     sizeof(char *) c     sizeof(char *) d    2*sizeof(int) e     sizeof(int *) i     sizeof(int) j     sizeof(int *) Total number of bytes ? What is the output of the following piece of code? (Use the above variable definitions). j = &i; *j = 50;                      /* i = 50 */ e = &d[0]; *e...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT