Computer Programming C Laboratory: Pointers C Programs

Write a C program to demonstrate the use of structure pointers

using pointers - C Programming

Write a C program to demonstrate the use of structure pointers.

While using structure pointer, be sure and take care of the precedence of operators, because the operators '‒>', '.', '()', and '[ ]' are frequently used in structure pointers.

/* C Program to demonstrate the use of structure pointers */

#include <stdio.h>

/* Structure book consists of bno, cost and pointer *bname[] */

struct book

{

        int bno;

        char *bname [20];

        int cost;

}

main()

{

/* Local definitions */

struct book_p[3],*ptr;

printf("\nEnter book details.....\n");

printf("Enter Book Number, Name, Cost..");

for(ptr=p;ptr<p+3;ptr ++)

        scanf("%d %s %d", &ptr‒>bno, ptr‒> bname, &ptr‒> cost);

        printf("STRUCTURE OUTPUT \n");

        ptr=p;

while (ptr<p+3)

{

        printf("%5d\t%‒20s \t%d\n",ptr‒>bno,ptr‒>bname, ptr‒> cost);

         ptr++;

} /* while */

getch();

} /* main */

OUTPUT

Enter book details.....

Enter Book Number, Name, Cost..

101 COMPUTERPRACTICE_1  240

201 COMPUTERPRACTICE_2 250

202 C++ AND JAVA

STRUCTURE OUTPUT

101 COMPUTERPRACTICE_1 240

201 COMPUTERPRACTICE_2 250

202 C++ AND JAVA 280

EXPLANATION: In main function ptr declared as a pointer. Using for loop the variable bno, bname and cost are read, then p is assigned to the pointer variable ptr. The while loop checks the condition (ptr<p+3) or not. If condition satisfied then prints, bno, bname, cost using pointer variable ptr and pointer variable get increment else the program terminated.

 

Computer Programming C Laboratory: Pointers C Programs : Tag: C Programming : - Write a C program to demonstrate the use of structure pointers


Computer Programming C Laboratory: Pointers C Programs



Under Subject


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation