Introduction
C Programming
C Advanced
Important C Programs
Modal Box
Tutorials
C is a very powerful and widely used language. It is used in many scientific programming situations. It forms (or is the basis for) the core of the modern languages Java and C++. It allows you access to the bare bones of your computer.C++ is used for operating systems, games, embedded software, autonomous cars and medical technology, as well as many other applications. Don't forget to visit this section...
Structure in C
Structure is the way to store different data types into a single variable.
Structure may be declared as following:
struct <structure name>
{
datatype varname;
datatype varname;
}
Example :
struct book
{
int pages;
float mrp;
}
Now we can declare the variable of book type too,
struct book b1,b2;
Program to take input and print details of three books using structure.
#include <stdio.h> #include <conio.h> void main() { struct book { int pages; float mrp; };
struct book b1,b2; //how to take input in structure variable. printf("enter the details for first book."); scanf("%d", &b1.pages); scanf("%f", &b1.mrp);
printf("enter the details for second book."); scanf("%d", &b2.pages); scanf("%f", &b2.mrp);
// similarly to print the structure variable. printf("details for first book"); printf("pages= %d price=%f\n", b1.pages, b1.mrp); printf("details for second book"); printf("pages= %d price=%f\n", b2.pages, b2.mrp); }
Video/ C Introduction
Watch video in full size