C Language

INTRODUCTION

It is a procedural programming language. Developed By Dennis Ritchie in 1972. Mainly Developed as a system programming language to write an operating system. It is considered as the base for other programming languages, that is why it is known as mother language.
It Can be defined as :-
  1. Mother Language.
  2. System Programming Language
  3. Structured Programming Language
  4. Mid Level programming language
  5. Procedure-oriented programming language

Beginning With C Programming

  1. Structure Of C Program
                        By structure, it is meant that any program can be written in this structure only. Writing a C program in any other structure will hence lead to a Compilation Error.

HEADER        #include<stdio.h>
MAIN          int Main(){
VARIABLE          int a = 10;
BODY              printf("%d",a);
RETURN            return 0; }

Component Of The Above Structure

Header File Inclusion:- Header File is a file with .h extension which contain c function declaration and macros definition. Some of C Header Files:-
  • stddef.h :- Define several useful types and macros.
  • stdint.h :– Defines exact width integer types.
  • stdio.h :– Defines core input and output functions.
  • stdlib.h :– Defines numeric conversion functions, pseudo-random network generator, memory allocation.
  • string.h :– Defines string handling functions.
  • math.h :– Defines common mathematical functions.
SYNTAX TO INCLUDE HEADER FILE IS :- #include<header_file_name>

Main Method Declaration:- After adding header file we have to write the main()function which is the entry point of every program in c Language.

SYNTAX TO DECLARE MAIN METHOD IS :- int main(){#rest_of_the_code}

Variable Declaration :- It refers to the variables that are to be used in the function. Please note that in the C program, no variable can be used without being declared. Also in a C program, the variables are to be declared before any operation in the function.

SYNTAX TO DECLARE VARIABLE IS :- data_type variable_name = value;

Body :- Body of a function in C program, refers to the operations that are performed in the functions. It can be anything like manipulations, searching, sorting, printing, etc.

Return Statement :- The return statement refers to the returning of the values from a function. This return statement and return value depend upon the return type of the function. For example, if the return type is void, then there will be no return statement. In any other case, there will be a return statement and the return value will be of the type of the specified return type.

FIRST PROGRAM :- Write a program to print your name.
            1    #include<stdio.h>
            2    int main(){
            3        printf("EduNext");
            4        return 0;
            5    }

Let us analyze the program line by line.
Line 1: [ #include <stdio.h> ] In a C program, all lines that start with are processed by preprocessor which is a program invoked by the compiler. In a very basic term, preprocessor takes a C program and produces another C program. The produced program has no lines starting with #, all such lines are processed by the preprocessor. In the above example, preprocessor copies the preprocessed code of stdio.h to our file. The .h files are called header files in C. These header files generally contain declaration of functions. We need stdio.h for the function printf() used in the program.

Line 2 [ int main() ] There must to be starting point from where execution of compiled C program begins. In C, the execution typically begins with first line of main().
The int written before main indicates return type of main(). The value returned by main indicates status of program termination. 

Line 2 and 5: [ { and } ] In C language, a pair of curly brackets define a scope and mainly used in functions and control statements like if, else, loops. All functions must start and end with curly brackets.

Line 3 [ printf(“EduNext”); ] printf() is a standard library function to print something on standard output. The semicolon at the end of printf indicates line termination. In C, semicolon is always used to indicate end of statement.

Line 4 [ return 0; ] The return statement returns the value from main(). The returned value may be used by operating system to know termination status of your program. The value 0 typically means successful termination.


1 comment: