My Experience — Story #1
Hello guys, Welcome. Thanks for clicking on this article. Hope you learn some stuff from my stories. Lets get started!
C is a general-purpose programming language. It has been closely related with UNIX operation system (an opensource alternative to windows). When UNIX was developed, both the OS and applications that run on it are written in C. Through it has been called as “System Programming language” because it is useful for writing compiles and operating system. It has been used equally well to write major programs in different domains.
For many years, the definition of ‘C’ was a reference manual in the first edition of “The Programming Language” in 1983 later the AMERICAN NATIONAL STANDARD INSTITUTE (ANSI) established a committee to provide modern comprehensive definition to C. The resulting definition was ANSI standards of ANSI ‘C’ was completed late in 1988. Modern compilers already support most of the features of standards.
Over the past few years, this language become one of the most popular programming languages. This is because of the simplicity in the language syntax and semantics. It is one of a very few high-level languages which can be looked like a low-level language.
Documentation Section:
It is an optional section used to write the comments regarding the program and the programmer. i.e., name of the programmer, date it is designed and so on.
The comments are written within the comment symbols /* — — — — — — — */
The code which is mentioned within the comment symbol is referred as non-executable code.
The compiler ignores it. The code will not have any effect on the program.
Link section:
It is the section where we link up the system library header files to our current program. So that the system library function present in those files could be utilized flexibly in our program.
The files are linked by means of a pre-processor directive #include
Example: #include<stdio.h>
Definition Section:
It is also an optional section used to define symbolic constants called macros. The nature of symbolic constant is that it cannot be varied or changed during the execution of the program. A symbolic constant is defined by means of a pre-processor directive #define
Example: #define PI 3.1423
Global Declaration Section:
It is also an optional section used to declare the global variable that can be accessed through out the program in any function. These are also referred as external variables. These variables should be declared outside all the functions
This sample has two functions,
- main() : A special function which will execute first whenever we run a program.
- printf() : A library function from standard input output library(stdio.h) used to print the (“character, string, float, integer, octal and hexadecimal values”) onto the output screen.
Pre-processors directives: These will Pre-process the program file, which is to be handed over to the compiler for the compilation.
Begin with a # (hash), # is a direction to the preprocessor
Syntax: #include<header file> or #include “header file”
Now let’s get started.
Personally, I prefer Dev C++ compiler over Borland TurboC++ or any other compilers for that matter.
Throughout this guide, we will be using “Dev C++” compiler.
- To save a C program press ctrl+s
- To compile a C program press F9
- To Run a compiled program press F10
- To compile and run press F11
- To create a new source file press ctrl+n
To get the C program output successfully it must pass through two environments.
1. Compile time environment
2. Runtime environment
During the compile time, it checks the syntax and Symantec errors and allocate memory for variables. During this time, it creates an object file with an extension .obj
During Run time, it performs computable instructions and input output statements etc. during this time, it creates an executable file with an extension .exe
The only way to learn a new programming language is, by writing programs in it. In C, the program to print Hello is
The first line of the program,
#include<stdio.h> provides all the necessary functions for out program.
Normally, you are free o give function whatever name you like but main function is special. Every ‘C’ program begins execution from the main function. This means that every ‘C’ program must have a main function.
Main will usually call other function to perform its job. User can call some user defined functions that you wrote and others from libraries provided. It is the best example of user defined function. It is not a system library function.
One method of communicating data between function is the calling function to provide a list of values. Known as arguments to the function. It passes the arguments to the called function by mentioning in the parenthesis. In this example, main is defined by a function that expects no arguments, indicated by ().
The statement of a function are enclosed in braces { }. The function main contains only one statement.
printf(“Hello”);
A function is called by naming it, followed by its arguments. So, this calls the function whose name is printf, with the argument “Hello”. Printf() is a library function that prints string of characters between the quotes. A sequence of characters in double quotes, like “Hello” is called as character string or string constant.
The escape sequence \n in the string is ‘C’ notation for the new line character which when printed advances the output to the left margin on the next line. If you leave out the \n (try) you will find that there is no line advanced after the output is printed.
Note: Suppose if you save a ‘C’ file it stores with an extension .c
In ‘C’ all variables must be declared before they are used at the beginning of the function and before by an executable statement. A declaration announces the properties of variables. It consists of a type name and a list of variables, such as
Int x,y,z;
The type int means that the variables listed are integers. Similarly, the type float means floating point, ie., Numbers that may have a fraction part.
‘C’ provides several other basic data types besides int and float. Some of them are
· Char Character — a single byte
· Short short integer
· Long long integer
· Double double precision floating point
Variables and constants are the basic data objects manipulated in a program
Declarations: List the variables to be used, and state what type they have and what their initial values are.
Operators: Specifies what to be done to them.
Expressions: Combine variables and constants to produce new values
That’s all for this story. In the next story I will go through some fundamentals in C. Thank You.
— Bharadwaj Yellapragada