We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 40bda25 + 0eec857 commit 373d27cCopy full SHA for 373d27c
DynamicMemoryAllocation
@@ -0,0 +1,29 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+struct course {
4
+ int marks;
5
+ char subject[30];
6
+};
7
+
8
+int main() {
9
+ struct course *ptr;
10
+ int noOfRecords;
11
+ printf("Enter the number of records: ");
12
+ scanf("%d", &noOfRecords);
13
14
+ // Memory allocation for noOfRecords structures
15
+ ptr = (struct course *)malloc(noOfRecords * sizeof(struct course));
16
+ for (int i = 0; i < noOfRecords; ++i) {
17
+ printf("Enter subject and marks:\n");
18
+ scanf("%s %d", (ptr + i)->subject, &(ptr + i)->marks);
19
+ }
20
21
+ printf("Displaying Information:\n");
22
23
+ printf("%s\t%d\n", (ptr + i)->subject, (ptr + i)->marks);
24
25
26
+ free(ptr);
27
28
+ return 0;
29
+}
0 commit comments