Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. (20 pts) What is the output of the fouowing program Show all your work. Draw

ID: 3808694 • Letter: 3

Question

3. (20 pts) What is the output of the fouowing program Show all your work. Draw the contents of the array and pay attention to the formatting of the output. ainclude Katdio.h> ain clude void print (int info int size) int i for (i i size; i++) printf d info [i]) printf ("In") int main() int i data, dataptr data (int malloc(4 sizeof (int)) for (i 0 i i++) data[i] 3 i; print (data,4) edata 5; dataptr data dataptr++; edat aptr 1; print (data,4); (data+2) 4; (dataptr+2) 2; print (data,4); free (data) return 0

Explanation / Answer

main.c

#include<stdio.h>
#include<stdlib.h>
void print(int *info, int size)
{
    int i;
    for(i=0;i<size;i++)
            printf("%d ",info[i]);
    printf(" ");
    return;
}
int main(){
    int i,*data,*dataptr;
    data=(int*)malloc(4*sizeof(int));
    for(i=0;i<4;i++)
    data[i]=3*i;
    print(data,4);//first time print function is called
    *data=5;
    dataptr=data;
    dataptr++;
    *dataptr=1;
    print(data,4);//second time print function is called
    *(data+2)=4;
    *(dataptr+2)=2;
    print(data,4);//third time print function is called
    free(data);
    return 0;
    }

Output :-

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote