Thursday, 30 May 2013

C Programming Language Tutorial – II (Basic Input/output, Structure of program, Compilation & running process)

Basic I/O Functions
  • In C, there are no special keywords to perform input/output operations.
  • These operations are carried out by using library functions.
  • All console I/O functions produce only text based outputs.
  • However most compilers include screen control and graphics functions in their libraries.

The important task of any programming language is to handle input/output. C supports a set of library functions to handle I/O.
For I/O operations printf() and scanf() functions are used. These are formatted functions that allow the input read from keyboard and output displayed on the monitor to be formatted as per our requirements.

printf()
Its name comes from print formatted.  Format specifiers request that the argument be formatted and inserted into the string.
    
printf(“format specifier”,list of variables);
 


scanf()
It accepts the data from keyboard, formats it in a certain way as specified by the format specifiers and stores it in a variable.

scanf(“format specifier”,list of addresses of variables);


Preprocessor
·   Preprocessor directives are the instructions given to the compiler.
·   Preprocessor directives begin with # (hash).
·   Preprocessor directives are often placed in the beginning of a program before the main() is declared.
·   They are not translated into machine language, but are operated upon directly by the compiler before the compiling process begins.


C Library
Every C program consists of modules of pieces of code called functions. A function aims at accomplishing a specific task. With in a program you can write your own functions or you can use the functions that are provided by C library.
C library provides a rich collection of functions to the programmer for most common programming tasks. The functions provided by the C program are a part of C standard library.
How to use library files.



#include<header file name>
#include<stdio.h>
#include<conio.h>
#include<math.h>


Some Important Library Functions:
  • main() – Start of program
  • clrscr() – Clear screen
  • getch() – To display output
  • gets() – To read string


Structure of C Program
// name of the program
Or
/* name of the program, name of author, date, brief description, modification details etc.*/
#include<headerfiles>
#define constants

Function prototype;  /* if you declared your own function*/

return type main()
{ /* prog begins*/
            Declaration of local variables;
            Executable part;
            return;
} /* end of main() */

User define function()
{
            Function code;
}



Compiling And Running Program

Source File
This is single program file written by programmer.
This file has names which end in .c by convention.

Compiler
It translates the program written by user into binary format which can be directly understood by underlying operating system.


Object File
These are consists of function definitions in binary form, but are not executable by themselves.
These are created from source code file.

Linker
It links together a number of object files to produce an executable file.

Executable File
These are produce as the out of program. It generally ends with .exe.

Tuesday, 28 May 2013

C Programming Language Tutorial – I (Data types, Identifiers, Variables, Keywords, Comments, Constant, Storage classes)

Data Types
C supports several types of data, each of which may be represented differently within the computer memory. The data type specifies data in computer memory.
C provides variety of data types.
  • Primitive or simple or inbuilt data types
- int, float, char, double
  • Derive data types
- Array, pointer
  • User define data types
- structure, typedof, enumeration

Data Type
Size(bytes)
Range
char
1
-128 to 128
int
2
-32767 to 32768
float
4
3.4e-38 to 3.4e+38
double
8
1.7e-308 to 1.7+308

Identifiers
Identifiers are the name given to various programming elements by a programmer. It is fundamental requirement of programming language.




Keywords
Keywords are the reserved identifiers and have predefined meaning to the compiler. They are always written in lower case. They cannot be use as name for user define identifier. C has 32 keywords.

auto
case
const
default
double
enum
float
goto
int
register
short
sizeof
struct
typedef
unsigned
volatile
break
char
continue
do
else
extern
for
if
long
return
signed
static
switch
union
void
while


Comments
Comments are used to enhance the readability and understanding of a program.
These are not executable statements and they are ignored by the compiler at the time of compilation.
Single line comments – (//)
Multi lines comments – (/* -----*/)

Constants
Constants are those whose value is fixed throughout the execution of program.
Each constant has a type, determined by its form and value.
·         Integer Constants – contains sequence of digit.
·         Character constants – encloses in a single quotation mark.
·         Floating constants – consists of integer part and a decimal point. It can be suffixed by f.

String Literals
It is a sequence of character surrounded by double quotation marks.

Escape Sequences
C supports some special backslash character constants that are used in output functions. These character constants are known as escape sequence characters.

Character
Escape Sequence
New line
\n
Horizontal tab
\t
Vertical tab
\v
Backspace
\b
Carriage return
\r
Form feed
\f
Backslash
\\
Single quote
\’
Double quote
\”
Question mark
\?
Bell (alarm / beep)
\a

Symbolic Constant
The constant values that have been given a name are called symbolic constants. In C you can create symbolic constants using #define. The subsequent use of symbolic constants within the program will automatically replace the specified value before the compilation of program.

Variables
Variables are named locations in memory that are used to hold a value that may be modified by the program. Every variable has two parts, a name and a data type.

Declaration of variable
Data-type varable;
int age;
char sname;
float avg;

Rules for declaration
-   Name of the variable should be start from alphabet.
-   Space is not allowed within the variable name.
-   Space is compulsory in between data type & variable name.
-   Only underscore character is allowed in variable name.
-   Variables are declared under a single data type are separated by comma.
-   Semicolon is used at the end of variable declaration.

Initializing a variable
A process of assigning value to the variable for the first time after its declaration is known as initialization.

    int no=10;

Scope of variable
·   Block scope – A variable is visible only with in the block in which it has been declared.
·   Function scope – A variable is visible to the entire function in which it has been declared.
·   File scope – A variable is visible to all the functions within a file.

Storage Class
Variables in C not only have data type, but also storage class that provides information about their location and visibility. A storage class determines the portion of a program within which the variables are accessible. C provides variety of storage classes.
·   auto – It declares an automatic variable that is visible only in the block in which it is declared.
·   static – It initialized variable to 0 unless another value is specified. A variable retains previous value between calls to the functions.
·   extern – It is accessible throughout the program. It is allocated when the program begins and deallocated when the program ends.
·   register – the register keyword specifies that the variable is to be stored in a machine register, if possible.


The volatile keyword is also use for declaration of variable which tell to compiler that the variable value is sudden change at any time.

C Programming Language Tutorial

C Language

Let us first elaborate some basic things. As you know that computer has divided into two parts namely Hardware and Software.

Hardware are physically appears parts. Examples are – Keyboard, Mouse, HD, RAM, CD-ROM etc.

Software further classified into following types:
  1. Operating System
Operating system is a inbuilt set of various types of software that are very useful and essential for the proper working of computer system.
Examples: DOS, WINDOW7, WINDOW8, MAC, Linux etc.

  1. Application Software
Application software is a set of inbuilt tools and commands useful for different types of applications. MS-Office, AutoCAD, Tally some are mostly used examples of software.

  1. Programming
Programming is a different approach of software because here you do not have inbuilt set of tools and commands rather you have a way to create and developed programs by using style and structure of programming language you selected for development.

Examples: C, C++, Java, .NET, PHP etc.


Let take a look at diagram of Evolution of Software:




    • Binary language
    It represents binary i.e. 0 and 1. Since computer can understand only 0 and 1.

    • Machine language
    It typically refers to a set of instructions which can be directly used by computer without intermediate process.

    • Assembly language
    In this language symbolic assembly code were used. These are highly dependent on hardware of machine and thus lacked portability.

    • Procedural Oriented Programming
    It is a structural language and known as basic programming language.

    • Object Oriented Programming
    It is a top most layer. Class and Object as well as various types of techniques are including in this type of programming language.

    For a new beginner of programming let us discuss in detail some basic   concepts

What is language?
Code or set of instructions written in such a manner that computer potentially understand.

Types of language:
  • Low Level Languages
When the sequence of instructions is in the form of a set of code then it is depends on machine. The operation codes will be different from one machine model to another, so it is necessary that programs need to be rewritten.

  • High Level Languages
These languages are not coded but they resemble ordinary English statements. The memory address is referred by symbolic names. It translates the program into machine language so it is made understand by computer system. The resulting program is known as object file and the original program is known as source file.

What is Programming?
Set of instructions written in logical flow.
Logic - Sequence of instructions.
Let us take example of sum of two numbers. What is logic or we call it as what is a sequence?-
1.     Input two numbers
2.     Perform process of sum
3.     Print sum as output
 i.e. How to perform given program within a sequence known as logic.

History of C
It is developed in the early 1970s by Ken Thomson and Dennis Ritchie. It was named ‘C’ because many of its features were derived form earlier BCPL (basic code for programming language) language which is known as ‘B’ language. It is core and powerful programming language.

C Language’s Features
  • A simple core language with multiple functionality such as Math’s, Console library functions,
  • Focus on procedural programming.
  • It is use for system development work.
  • It is also use for developing application program as well as hardware control programs.
  • It provides variety of data types for structured program so it is powerful.
  • C compilers available for almost all types of PC’s.
  • The UNIX operating system was developed using C.
  • C is DOS based programming language.
  • Programs written under C are fast & efficient to execute.
Operators
An operator specifies an operation to be performed. An operator takes one or more operands, performs specified action on them, and returns desired result.

Operators
Symbols
Arithmetic
+, -, *, /, %
Relational
>, <, >=, <=, !=, ==
Logical
&&, ||, !
Assignment
=, +=, -=, *=, /=,%=
Increment
++
Decrement
--
Bit wise
&, |, ^, <<, >>, ~
Conditional
?, :

Saturday, 25 May 2013

Introduction to me & my blog

I am starting this blog with the intention to give you training about computer programming languages.

Let me first introduce my self. I am teaching programming languages in computer training institute since 8-9 years.
I give training in C, Cpp, Java, VB.Net, C#.Net, Oracle and also train students in CorelDraw, Photoshop, HTML, DreamWeaver(Web Designing sostware). I have a experience of software development in Autocad automation by using Visual Basic 6.0 programing language. I have also developed software for college student of MCA, MCS, Diploma. These software are mainly database related. I have handled databases in MS-Access, MS-SQLServer, Oracle etc.

For all this journey I am very grateful to my elder brother Mr. Shantaram Pardeshi and owner of institute where I am teaching from a long time Mr. Vinod Deshmulh. These people always encourage me in my work. Guidance and support from these people always encourage me to learn more and more in this field. Adopt knowledge of new technologies.

I recently started learning Android. This technology is used for mobile programming. 

















Popular Posts