Q:

Write a C program for Student details using pointer and structure

0

Write a C program for Student details using pointer and structure. Here’s simple program to read and print student details using pointer in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

What are Pointers?


A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.

 
 

The general form of a pointer variable declaration is −

  • type *var-name;

Here, type is the pointer’s base type; it must be a valid C data type and var-name is the name of the pointer variable.

The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer.

 

The unary or monadic operator & gives the “address of a variable’”.

The indirection or dereference operator * gives the “contents of an object pointed to by a pointer”.


Below is the source code for C program for Student details using pointer and structure which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :

/*  C program to read and print student details using pointer  */

#include <stdio.h>

struct student
{
    char    name[30];
    int     roll;
    float   perc;
};
int main()
{
    struct student  std;        //structure variable
    struct student  *ptr;       //pointer to student structure

    ptr= &std;                  //assigning value of structure variable

    printf("Enter details of student :: \n");
    printf("\nEnter Name of student :: ");
    scanf("%s",ptr->name);
    printf("\nEnter Roll No of student :: ");
    scanf("%d",&ptr->roll);
    printf("\nEnter Percentage of student :: ");
    scanf("%f",&ptr->perc);

    printf("\nEntered details of student are :: \n");
    printf("\nName : %s \n\nRollNo: %d \n\nPercentage: %.02f\n\n",ptr->name,ptr->roll,ptr->perc);

    return 0;
}

Output : :


/*  C program to read and print student details using pointer  */

Enter details of student ::

Enter Name of student :: CodezClub

Enter Roll No of student :: 12345

Enter Percentage of student :: 89

Entered details of student are ::

Name : CodezClub

RollNo: 12345

Percentage: 89.00


Process returned 0

Above is the source code for C program for Student details using pointer and structure which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Pointer Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C program to Print string using pointers... >>
<< C program to count number of vowels and consonants...