Saturday, 8 September 2018

Using Escape sequences

1. New line character(\n)

 \n is the new line character ,it moves the cursor to starting of next line.

Input:-

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello User");
printf("\nwelcome to C");
getch();
}


Output:-

Hello User
welcome to C



2. Tab character(\t)

\t is the horizontal tab character,it moves the cursor a tab width.

Input:-

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello \tUser");
printf("\nHi \tUser");
getch();
}

Output:-

Hello           User
Hi                User




3. Carriage return character(\r)

Input:-


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello\r");
getch();

}

Output:-

Hello






















Thursday, 6 September 2018

Function , compilation and execution

About #include and main()

In C and C++ languages, the symbol of # is called pound and any statement which begins with # is called as pre-processor directives.

Some of the pre-processor directives are -

#include
#define
#undef
#if
#else
#elif
#endif
#ifdef
#ifndef

Amongst all of them, the most commonly use directive is the #include directive which is called as file inclusion directive.Whenever the processor find these directives in our programme this take the following actions -
1. It reads the name of the file mentioned in angular bracket.
2. It copies the entire coding of the mentioned header file and paste it in our programme in place of the #include statement.

Due to this number of statement in our program are increased and a separate copy of our program gets created called as expanded source code. This expanded source code is then converted into the machine code by compiler.

What is a function and why do we write main()?

In C programming, a function is a set of statements having a particular name followed  by
 pareldisis "()" and every C program contains one and more functions.

Amongst these functions the most important is the function main(). This is because whenever we execute our C program, its  execution always begins from the function main().

Can we compile a C program without main()?

YES,we can compile a C program even if it is not having the function main() but we can never execute a C program without main().This is because compilation of a program always starts from the first line but its execution which is done by operating system , always begins from main().So we can say that function main() is the entry point of execution of our program.

Compiling a C program-

The second step in programming is to compile our programs. Compilation means conversion of the program from source code to the machine code.Whenever we compile a C program the compiler take two actions-
1. It checks our program for syntax error.
2. If no syntax error is present, the most compiler successfully converts our program to machine code.But if our program contain even a single error , the compilation step and machine code is not generated.



Execution of C program-

To run a c program in TURBO IDE we have two options-
1.Using the run menu from menu bar.
2.Using keyboard shortcut alt+R or ctrl+F9.

Whenever we run a program in TURBO IDE , the output gets displayed on the console window but to see this out, we have to open the console window and this can be done using another key combination called alt+F5.

Using the function getch()

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello User");
getch();
}


The function getch() stands for get character and is available inside the headerfile conio.h .
Whenever we call the function getch() in our program C language takes two actions-
1.The execute pauses.
2.The console window gets opened up.
So if we call getch() at the end then we don't have to use alt+F5. There is another very important use of getch() which is to accept hidden inputs.

























Wednesday, 5 September 2018

About Header Files and Functions

                                  About Header Files

In c and c++ language any file which have the extension .h is called as a headerfile. These header file are developed by the company which design the compiler or IDEs of C language and they contain a huge collection of predefined programs called as functions.

Methamatical functions are-
-sqrt()
-pow()
-sin()
-cos()
-pan()
-log()
These all are available in a headerfile called math.h

Graphics related functions are-
-circle()
-rectangle()
-bar()
-polygon()
These all are available in the headerfile called graphics.h

Uses-

Now whenever we write a programme in C language , we can use these functions to make our task simpler . But before using any predefine functions in our programme we must compulsaryly attached the require header file using the command -
#include

What is stdio.h and why do we use it?

stdio = standard input-output

standard input means keyboard and standard output means monitor. Thus the headerfile stdio.h provides us support for keyboard and monitor in our programmes . This support is given in the form of two functions printf() and scanf().

printf() = used for displaying text on monitor called as output.
scanf() = used for accepting values from the user called as input.

What is conio.h and why do we use it?

conio = console input-output

console represent output window that is the window ware the result of execution of our programme is displayed.
Although the headerfile conio.h does not produce this window but it provides us some very useful functions  to manage the window some of it importance functions are -
1. clrscr() = used for cleaning the console window.
2. textcolor() = used for changing font colour of the console window.
3. gotoxy() = used for setting cursor position on console window.
4. getch() = used for pausing the console window.







C Language

C is a procedural programming language.It was initially developed by Dennis Ritchie and Brian Kerninghn  in 1972.

Steps required while developing a programme:-

1. Writing the source code.
2. Compilation of the source code.
3. Execution of the machine code.

Some popular IDEs(Integrated development environments)

1. Turbo c++
2. Code blocks
3. Dev c++
4. Visual studio
5. X-code

These all above IDEs are Compilers.

1. First C programme-

#include<stdio.h)
#include<conio.h)
void main()
{
clrscr();
printf("Hello User");
getch();
}



Output:

Hello User