15/04/2016

C Program to Store Student Information Using Structures And Pointer

Problem:- Write A C Program to Store Information Using Structures With Pointer With Dynamically Memory Allocation In Structure In C or c program to store information of 10 students using structure or c program to store information using structures with dynamic memory allocation or dynamic memory allocation for structures in c or dynamic memory allocation in c programming examples or c program using structures employee details or dynamic memory allocation for array of structures in c or memory allocation for structure members in c or c program examples using structures.

What Is Pointer?.

The pointer is a variable which holds the address of another variable. If you want to practice more on pointer question Click here.

Defining a structure

struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.

Syntax :

struct structure_name
{
//Statements
};

Solution:-

#include <stdio.h>
#include<stdlib.h>
struct name {
   int a;
   char c[30];
};
int main(){
   struct name *ptr;
   int i,n;
   printf("Enter The No. : ");
   scanf("%d",&n);

/* Allocates the memory for n structures with pointer ptr pointing to the base address. */
   ptr=(struct name*)malloc(n*sizeof(struct name));
   for(i=0;i<n;++i){
       printf("Enter string and integer respectively:\n");
       scanf("%s%d",&(ptr+i)->c, &(ptr+i)->a);
   }
   printf("Displaying Infromation:\n");
   for(i=0;i<n;++i)
       printf("%s\t%d\t\n",(ptr+i)->c,(ptr+i)->a);
   return 0;

}

Output:-


C Program to Store Student Information Using Structures And Pointer


You May Also Like


1. C Program To Insert An Element Desired or Specific Position In An Array

2. C Program For Remove Duplicates Items In An Array

3. C Program To Delete Element From Array At Desired Or Specific Position

4. C Program For Print "I AM IDIOT" Instead Of Your Name Using Array

5. C Program For Check String Is Palindrome Or Not Using For Loop

6. C Program For Convert All Input String Simultaneously Into Asterisk ( * )

7. C Program For Calculator Using Switch Case

8. C Program For Find A Grade Of Given Marks Using Switch Case

9. C Program For Finding Radius Circumference Using Switch Case

10. C Program For Remove All Vowels From A String Using Switch Case



Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: