Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>
int main()
{
int *marks;
printf("Enter four marks:");
for(int i = 0;i<4;i++)
scanf("%d",&marks[i]);
printf("Marks you entered are:");
for(int i=0;i<4;i++)
printf("%d ",marks[i]);
return 0;
}

What I have tried:

The program did not give any output neither did it show any error
Posted
Updated 2-Oct-18 9:27am

You declared
int *marks;

You didn't allocate any memory for it.   You're somewhat fortunate your application didn't just crash.

Something like
marks = (int *)malloc(4*sizeof(int));


 
Share this answer
 
v2
Comments
CPallini 2-Oct-18 17:19pm    
5.
Quote:
Why doesn't the compiler show an error for *marks being used as marks[I]?

Because the language definition says that the name of an array is a pointer to the first element. So marks is both a pointer and an array t the same time; the usage is available either way you declare it.
C++
int arr[10];
int i1 = arr[0];
int i2 = *arr;
Is all valid, as is:
C++
int *arr = (int*) malloc(40);
int i1 = arr[0];
int i2 = *arr;
 
Share this answer
 
Comments
CPallini 2-Oct-18 17:19pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900