Sunday, April 28, 2019

Variable in C Language

Variable is an identifier which holds data or another one variable. It is an identifier whose value can be changed at the execution time of program. It is used to identify input data in a program.
Syntax:
variable in c

Syntax

Variable_name = value;

Rules to declare a Variable

To Declare any variable in C language you need to follow rules and regulation of C Language, which is given below;
  • Every variable name should start with alphabets or underscore (_).
  • No spaces are allowed in variable declaration.
  • Except underscore (_) no other special symbol are allowed in the middle of the variable declaration (not allowed -> roll-no, allowed -> roll_no).
  • Maximum length of variable is 8 characters depend on compiler and operation system.
  • Every variable name always should exist in the left hand side of assignment operator (invalid -> 10=a; valid -> a=10;).
  • No keyword should access variable name (int for <- invalid because for is keyword).
Note: In a c program variable name always can be used to identify the input or output data.

Variable declarations

This is the process of allocating sufficient memory space for the data in term of variable.

Syntax

Datatype variable_name; int a;
variable declaration
If no input values are assigned by the user than system will gives a default value called garbage value.

Garbage value

Garbage value can be any value given by system and that is no way related to correct programs. This is a disadvantage of C programming language and in C programming it can overcome using variable initialization.

Variable initialization

It is the process of allocating sufficient memory space with user defined values.

Syntax

Datatype nariable_name=value;

Example

int  b = 30;
variable initilization

Variable assignment

It is a process of assigning a value to a variable.

Syntax

Variable_Name = value

Example

int  a= 20;
int b;
variable Assignement

Example

b = 25; // --> direct assigned variable
b = a;  // --> assigned value in term of variable
b = a+15;  // --> assigned value as term of expression
variable Assignement





Variable Declaration Rules in C

To Declare any variable in C language you need to follow rules and regulation of C Language, which is given below;
  • Every variable name should start with alphabets or underscore (_).
  • No spaces are allowed in variable declaration.
  • Except underscore (_) no other special symbol are allowed in the middle of the variable declaration (not allowed -> roll-no, allowed -> roll_no).
  • Maximum length of variable is 8 characters depend on compiler and operation system.
  • Every variable name always should exist in the left hand side of assignment operator (invalid -> 10=a; valid -> a=10;).
  • No keyword should access variable name (int for <- invalid because for is keyword).
Note: In a c program variable name always can be used to identify the input or output data.

Variable declarations

This is the process of allocating sufficient memory space for the data in term of variable.

Syntax

Datatype  variable_name;
int  a;
variable declaration
If no input values are assigned by the user than system will gives a default value called garbage value.

Garbage value

Garbage value can be any value given by system and that is no way related to correct programs. This is a disadvantage of C programming language and in C programming it can overcome using variable initialization.

Keywords,Constant in C

Keyword is a predefined or reserved word in C library with a fixed meaning and used to perform an internal operation. C Language supports 32 keywords.
Every Keyword exists in lower case latter like auto, break, case, const, continue, int etc.

32 Keywords in C Language

autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constfloatshortunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile




Comments in C

Generally Comments are used to provide the description about the Logic written in program. Comments are not display on output screen.
When we are used the comments, then that specific part will be ignored by compiler.
In 'C' language two types of comments are possible
  • Single line comments
  • Multiple line comments

Single line comments

Single line comments can be provided by using / /....................

Multiple line comments

Multiple line comments can be provided by using /*......................*/
Note: When we are working with the multiple line comments then nested comments are not possible.
comment in c

Rules for Writing Comments

1. Program contains any number of comments at any place.

Example

// header files
#include<stdio.h>
#include<conio.h>

void main()
{
// variable declaration
int a,b,c;
a=10;
b=20;
c=a+b;
printf("Sum= %d",c);
getch();
}
2. Nested Comments are not possible, that means comments within comments.

Example

void main()
{
/*
/*      comments   */
*/
}
3. Comments can be splits over more than one line.

Example

void main()
{
/* main   
   function
   body part
*/
}
4. Comments are not case sensitive.

Example

void main()
{

/*  MAIN Function BODY   */

}
5. Single line comments start with "//"

Example

void main()
{

// Single line comment

}

Compiler in C

A compiler is system software which converts programming language code into binary format in single steps. In other words Compiler is a system software which can take input from other any programming language and convert it into lower level machine dependent language.
C Compiling

Interpreter

It is system software which is used to convert programming language code into binary format in step by step process.

Assembler

An assembler is system software which is used to convert the assembly language instruction into binary format in step by step process. An assembler is system software which is used to convert the assembly language instruction into binary format.

Compiler Vs Interpreter

NoCompilerInterpreter
1Compiler takes Entire program as input at a time.Interpreter takes Single instruction as input at a time.
2Intermediate Object code is generatedNo Intermediate Object code is generated
3It execute conditional control statements fastly.It execute conditional control statements slower than Compiler
4More memory is required.Less memory is required.
5Program need not to be compiled every timeEvery time higher level program is converted into lower level program
6It display error after entire program is checkedIt display error after each instruction interpreted (if any)
7Example: CExample: BASIC

Source Code Vs Object Code

Difference between source code and object code.

Source Code

  • Source code is in the form of Text form.
  • Source code is Human Readable Code.
  • Source code is Generated by Human or Programmer.
  • Source code is receive Compiler as a Input.

Object Code

  • Object Code is in the form of Binary Numbers.
  • Object Code is in Machine Readable formats.
  • Object Code is Generated by Compiler.
  • Object Code is Generated by Compiler as a Output.

TC Editor

TC Editor is very simple and easy to use; here i will give you all tips related to TC Editor and some shortcut keys related to TC Editor which is very useful at the time of coding. Turbo C is a most common C language compiler. Below i will discuss all about its Interfaces.
TC Editor

TC Editor

The interface of Turbo C is very simple. When IDE screen appears, the menu bar is activated. It contains various menus such as;
  • File: This menu contains group of commands used for save , edit , print program, exit from Turbo C editor etc.
  • Edit: This menu contains group of commands used for editing C program source code. Example Copy, Cut, Paste, Undo etc.
  • Search: This menu contains group of commands used for searching specific word as well as replacing it with another one.
  • Run: This menu contains group of commands used for running C program.
  • Compile: This menu contains group of commands used for compiling C program.
  • Debug: This menu contains group of commands used for debugging C program.
  • Project: This menu contains group of commands used for opening, closing and creating projects.
  • Options: This menu contains group of commands used for configuring IDE of Turbo C and setting up directories etc.
  • Windows: This menu contains group of commands used for opening, closing various windows of IDE.
  • Help: This menu is used to get help about specific topic of C language. Similarly to get help about a specific keyword or identifier of C.

Shortcut keys Related to TC Editor

  • Alt + x : Close TC Editor.
  • Clt + f9 : Run C Program.
  • Alt + f9 : Compile C Code.
  • Alt + Enter : Get Full Screen or Half Screen TC Editor.
  • Clt + y : Delete complete line above the cursor.
  • Shift + Right arrow : Select Line of Code.
  • Clt + Insert : Copy.
  • Shift + Insert : Paste.
  • Shift + Delete : Delete.

Installation of TC

Installation of TC is very simple just download turbo C or C++ and run .exe files
When you install the Turbo C compiler on your system, then TC directory is created on the hard disk and various sub directories such as INCLUDE, and LIB etc. are created under TC.
TC folder Details

  • INCLUDE :Contain the header files of C.
  • LIB: Contain the library files of C.
  • BGI: Contain Graphics related files.
  • BIN: Contain .exe, .obj etc files.

Turbo C For Window(xp, 7, 8)

Previously Turbo C are not work properly on Window 7 and its above versions. Here you can get Turbo C for Window 7 and its above versions.
  • Turbo C For Window 7 and 8 

Applications of C

Mainly C Language is used for Develop Desktop application and system software. Some application of C language are given below.
  • C programming language can be used to design the system software like operating system and Compiler.
  • To develop application software like database and spread sheets.
  • For Develop Graphical related application like computer and mobile games.
  • To evaluate any kind of mathematical equation use c language.
  • C programming language can be used to design the compilers.
  • UNIX Kernal is completely developed in C Language.
  • For Creating Compilers of different Languages which can take input from other language and convert it into lower level machine dependent language.
  • C programming language can be used to design Operating System.
  • C programming language can be used to design Network Devices.

Features of C

It is a very simple and easy language, C language is mainly used for develop desktop based application. All other programming languages were derived directly or indirectly from C programming concepts. This language have following features;



  • Simple
  • Portability
  • Powerful
  • Platform dependent
  • Structure oriented
  • Case sensitive
  • Compiler based
  • Modularity
  • Middle level language
  • Syntax based language
  • Use of Pointers

Simple

Every c program can be written in simple English language so that it is very easy to understand and developed by programmer.

Platform dependent

A language is said to be platform dependent whenever the program is execute in the same operating system where that was developed and compiled but not run and execute on other operating system. C is platform dependent programming language.
C is Platform Dependent
Note: .obj file of C program is platform dependent.

Portability

It is the concept of carrying the instruction from one system to another system. In C Language .Cfile contain source code, we can edit also this code. .exe file contain application, only we can execute this file. When we write and compile any C program on window operating system that program easily run on other window based system.
features of c
When we can copy .exe file to any other computer which contain window operating system then it works properly, because the native code of application an operating system is same. But this exe file is not execute on other operation system.

Powerful

C is a very powerful programming language, it have a wide verity of data types, functions, control statements, decision making statements, etc.

Structure oriented

C is a Structure oriented programming language.Structure oriented programming language aimed on clarity of program, reduce the complexity of code, using this approach code is divided into sub-program/subroutines. These programming have rich control structure.

Modularity

It is concept of designing an application in subprogram that is procedure oriented approach. In c programming we can break our code in subprogram.
For example we can write a calculator programs in C language with divide our code in subprograms.

Example

void sum()
{
 .....
 .....
}
void sub()
{
 .....
 .....
}

Case Sensitive

It is a case sensitive programming language. In C programming 'break and BREAK' both are different. It is also main feature of C Language.
If any language treats lower case latter separately and upper case latter separately than they can be called as case sensitive programming language [Example c, c++, java, .net are sensitive programming languages.] other wise it is called as case insensitive programming language [Example HTML, SQL is case insensitive programming languages].

Middle Level Language

C programming language can supports two level programming instructions with the combination of low level and high level language that's why it is called middle level programming language. C is middle lelev programming language it is one of the most importaint feature of C.

Compiler Based

C is a compiler based programming language that means without compilation no C program can be executed. First we need compiler to compile our program and then execute.

Syntax Based Language

C is a strongly tight syntax based programming language. If any language follow rules and regulation very strictly known as strongly tight syntax based language. Example C, C++, Java, .net etc. If any language not follow rules and regulation very strictly known as loosely tight syntax based language.
Example HTML.

Efficient use of Pointers

Pointers is a variable which hold the address of another variable, pointer directly direct access to memory address of any variable due to this performance of application is improve. In C language also concept of pointer are available.

Overview of C

C is a computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX Operating System. C is a simple and structure oriented programming language.
C Basic
C is also called mother Language of all programming Language. It is the most widely use computer programming language, This language is used for develop system software and Operating System. All other programming languages were derived directly or indirectly from C programming concepts.
Dennis Ritchie
In the year 1988 'C' programming language standardized by ANSI (American national standard institute), that version is called ANSI-C. In the year of 2000 'C' programming Language standardized by 'ISO' that version is called C-99

Where we use C Language

C Language is mainly used for;
  • Design Operating system
  • Design Language Compiler
  • Design Database
  • Language Interpreters
  • Utilities
  • Network Drivers
  • Assemblers

Basics of C Programming

C is a computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX Operating System. C is a simple and structure oriented programming language.
C is also called mother Language of all programming Language. It is the most widely use computer programming language, This language is used for develop system software and Operating System. All other programming languages were derived directly or indirectly from C programming concepts. Here we discuss complete C Tutorial in simple and easy way. C is a programming language that serves as a medium for programmer to instruct computer to do a job or making programs/softwares.

History of C

C language is developed by Mr. Dennis Ritchie in the year 1972 at bell laboratory at USA, C is a simple and structure Oriented Programming Language.
In the year 1988 C programming language standardized by ANSI (American national standard institute), that version is called ANSI-C. In the year of 2000 C programming language standardized by ISO that version is called C-99. All other programming languages were derived directly or indirectly from C programming concepts.

Prerequisites

Before learning C Programming language or this C Tutorial no need of knowledge of any Computer programming language, C is the basic of all high level programming languages. C is also called mother Language.

Why learning C Programming is a must?

C is a procedural programming language. It was initially developed by Dennis Ritchie between 1969 and 1973. It was mainly developed as...