structure of c program

structure of C program is composed of preprocessor commands a global declaration section and one or more function the preprocessor directive contained special instruction that indicate how to prepare the program for completion one of the most important and commonly used preprocessor commands is include which tells the compiler that to execute the program some information is needed from the specified header files

structure of C program contain one or more function where a function is defined as a group of statements C function are written in a global sequence to perform a specific task the main function is the most important function and it's a part of every C program that the execute execution of a C program begins at the preprocessor commands each and every C program contain the main function.

  • Preprocessor directives
  • Global declarations
  • main()
    Local declarations statements

structure of C program contains the following parts
  • Preprocessor directives
  • Functions
  • Variables declarations
  • Statements & Expressions
Preprocessor directives

The preprocessor directives that comes as the first statement in our code all preprocessor directive start with symbol hash(#) the #include statement tells the compiler to include the standard input output libraries or header files in C program
such as #include <stdio.h>
#include <conio.h>


Each and every C program contains a main() function which is the starting point of the C program

Variables declarations

In variable declaration section declared the required variable used in the c program

Statements & Expressions

Statements are the “commands” or “line of code” that can be executed .
Every statement in the main function ends whit semi colon (;).
such as return 0;

How to write c program

#include <stdio.h> // Preprocessor directives
int main() // Functions
char str[] = "C program"; //Variables declarations
printf("%s",str); // Statements & Expressions
return 0;

Structure Of C Program

In this article we will name things and manage complexity by writing small C programs loosely based on the program structure, which discuss how to write a good C main function. The first section examines how the C code is formatted and the different entities are named.

In lines 20-24 we explain and initialize the structure called the company (type struct company) and its substructures.

To actually create a single structure, the isTo () syntax accesses all variables in the structure. To initialize the C + + structure, we need to assign the values in the correct order, here is an example program. We can declare the structure database as we have it, but vice versa, we give ourselves the opportunity to declare a structure variable somewhere in our program, based on its size. The trick is that we can either explain it or initialize it, as I have just shown you, and here we do both. By declaring the c + + structure variable p1, we also initialize its p2, p3, and p4

It is important here that we use a structure type in our code, so we should define the structure in the header file and then not include the variable definitions in their definition. Each variable declared in a structure declaration list is defined as a member of the type of this structure.

To use this structure, we need to create a C program with product variables whose product structure is the same as the one in the header file of the C + + program.

When we pass a structure variable to a function, we assign a copy of the original structure as a formal argument to the print _ struct () function. When we start using pointers to structures, it can become a problem if we have more than one record structure type we want. Structures of standard integers and floating point numbers do not suffer from this problem, but objects and structures represent a single row in memory, so we create an array of structure objects. Unlike arrays, the name of a structure variable is not a pointer, and when structure pointers are output to the function (structure), any attempt to change the value of that structure results in a compilation error.

If we have more than one record structure type (e.g. integers, floating point numbers, etc.), we must have a pointer pointing to that structure.

When we declare a structure, it is not possible to declare a function that accepts any type of structure as a name. It is necessary to call the structure at some point (the structure at this point), because when we use it later, it is accompanied by a struct keyword that makes its nature perfectly clear each time we use it. Note that every time we want to use structures as parameters in a function, we need to define and apply them correctly. We can do this by using struct keywords in the same way we do with other types of functions in C.

When we call a function and pass a structure, the stack parameter will make a copy of the structure when the function is called. However, we can declare members who appear with a tag in each structure type. You can also throw a pointer to the first member of any structure, as a pointer to all pointers in the attached structures.

When we declare a structure, we can create instances and declare variables for that structure at a later point in time. For example, if we have declared a variable of type int or char, you can define variables of type struct type and then declare them the same way.

A structure can contain variables of type int, char, struct, int, or char type, and other variables such as ints, strings, arrays, objects, functions, variables, and more.

The declaration of a structure must begin with the struct keyword, followed by its name and its member variables in brackets. The structure tag can be used after the structure type is defined, but not before or after.

tag is the name of the entire structure type, and members are variables within the structure. Tag is a name for the entire structure and all its members, be they variables or structures. Tags are the names of whole types of structures, but members act as variables within the structure.

To associate two variables, we can use a powerful data construct in the C language called a structure to associate them with the other.

A structure is a custom data type and, like any built-in data type, it can be a return function. In the C language, it is illegal to access the members of a structure via the dot operator, but if the structure contains another structure, we also use the dot operator to access nested structures with nested structure members. Therefore, passing structure objects to a function and passing them to a function is the same, because structure objects represent structures. A structure can pass function as its object and structure functions as its object.

c programming examples