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. ");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.