C PROGRAMMING: STRUCTURE AND DATA TYPES PART-1

C programming : structure and data types

INTRODUCTION TO DATA TYPES:

In the C programming language, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in form of declarations for memory locations or variables. Data types also determine the types of operations or methods of processing of data elements.

But before understanding the data types in more detail, firstly we have a look at the structure of the C program.

STRUCTURE OF C PROGRAM :

But before seeing the syntax of C programming, we firstly define in a very simple language what is “syntax”?

SYNTAX: It is a method or format of writing a programming language.

#include<stdio.h>  // header file
int main()         //main() function must be there
{
   int i;          //data type declaration
   //Asking users for input   //Single line comment
   printf("Enter any value");   
   scanf("%d",&i);
getch();     // Semicolon after each statement

 return 0;
}  //Program enclosed within curly braces

This is a basic syntax, on the basis of which we write our program.

some important terms:

  • Printf – Use to print the character, result or output.
  • Scanf – Use to read a character or a value assign.
  • A semicolon (;) – It is very necessary to use after every statement.
  • Clrscr(); – This term is used to clear screen.
  • Getch(); – This term is used to hold the screen.
  • Open brace( { ) – Always used after main() / starting of the program.
  • Close brace( } ) – Always used in the end of program.

In this part, we will learn to use scanf() function to take input from the user, and the printf() function to display output to the user. In C PROGRAMMING, printf() is one of the main output function. It sends the output on the screen. For example,

Example 1- c output

#include<stdio.h>
int main()
{
  printf(" I love C Programming");
   // It display the result on the screen.
   return 0;
} 

output

C Programming

How does your program work when you execute it ?

  • All valid C program must contain the main() function. Your code starts executing from the start of the main() function.
  • The printf() is a library function to send formatted output to the screen. This function prints the string inside quotations.
  • Without including stdio.h header file we can’t use printf() in our program. So, to use printf() in our program, we need to include stdio.h header file using the #include<stdio.h> statement.
  • The return 0; statement inside the main() function is the “Exit status” of the program. It’s optional.

FLOW OF A C PROGRAM:

  1. Preprocessing
  2. Compilation
  3. Assembly
  4. Linking
  5. Loading

DATA TYPES IN C:

  1. Basic data types:- int, float, char, double
  2. Derived data types:- array, pointer, structure, union
  3. Void data types:- void ( here void means “empty” )

OPERATORS IN C:

An operator is a symbol used to perform operations in a given programming language. For example, 3+4=7. Here 3 is an operand, + is an operator, 4 is an operand.

TYPES OF OPERATORS IN C:

1- Arithmetic operators:

  1. + addition
  2. – subtraction
  3. * multiplication
  4. / division
  5. % modulus( it give us reamainder )

2- Relational operators:

  1. == ( is equal to )
  2. != ( is not equal to )
  3. > ( greater than )
  4. < ( Less than )
  5. >= ( greater than or equals to )
  6. <= ( less than or equals to )

3- Logical operators:

  1. && ( AND )
  2. | | ( OR )
  3. ! ( NOT )
In our previous article we already discuss the importance of C programming. And from this article we will discuss each operators later in more detail, but firstly we are going to focus on "DATA TYPES".

data types :

Data types is of two types :

  1. Primary data types : E.g. character, integer, float, double.
  2. Secondary data types: E.g. Array, pointer, structure.

Data types of variable :

  1. Character (char) –The most basic data type in C. It stores a single character. It stored 1 byte. [ Size of each data types depends on the architecture ]. example , char = ‘a’ , ‘G’ , ‘1’ ,….
  2. Integer(int) – An integer variable is used to store an integer. It stored 2 bytes, example , int = 2, 467, 67, 5 ,….
  3. Float – It is used to store decimal numbers with single precisions. It stored 4 bytes, example, float= 11.3 ,7.4456 , 7.00 ,…..
  4. Double – It is used to store decimal numbers with double precisions. It stored 8 bytes.
In our next part we will discuss each data types in more details along coding.
See you next time...
Scroll to Top