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

Ok so I need the program to print out the integer that the pointer points to. I

ID: 3553602 • Letter: O

Question

Ok so I need the program to print out the integer that the pointer points to. I cannot get it to do this. What am I doing wrong? It says "segmetation default". I am working in C.



#include <stdio.h> //This is C standard library.


void function(int *); // This does not require a return type for function


void main()

{

int num;


printf("Enter an integer value: ");

scanf("%d",num);

function(&num);



}

void function(int *p)

{


printf(" The integer is: %d ",*p);

printf("The program crashes my command prompt when ran. ");

printf("After the & is added it allows the program to runs. ");

printf("The scanf acts basically as a pointer which needs to be provided. ");


}


Explanation / Answer

#include <stdio.h> //This is C standard library.


void function(int *); // This does not require a return type for function


void main()

{

int num;


printf("Enter an integer value: ");

scanf("%d",&num); //here was the mistake

function(&num);



}

void function(int *p)

{


printf(" The integer is: %d ",*p);

printf("The program crashes my command prompt when ran. ");

printf("After the & is added it allows the program to runs. ");

printf("The scanf acts basically as a pointer which needs to be provided. ");


}

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