[go: up one dir, main page]

0% found this document useful (0 votes)
56 views13 pages

Starting of C

- C was developed at Bell Laboratories in the early 1970s by Dennis Ritchie. It was influenced by an earlier language called B. - C is a general-purpose programming language that is relatively simple and reliable. It was initially designed to be compiled to write operating systems like UNIX. - Key features of C include being portable, structured, high-level but with low-level capabilities. It uses keywords, variables, data types, functions, header files and libraries to write programs.

Uploaded by

Manish Tomar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views13 pages

Starting of C

- C was developed at Bell Laboratories in the early 1970s by Dennis Ritchie. It was influenced by an earlier language called B. - C is a general-purpose programming language that is relatively simple and reliable. It was initially designed to be compiled to write operating systems like UNIX. - Key features of C include being portable, structured, high-level but with low-level capabilities. It uses keywords, variables, data types, functions, header files and libraries to write programs.

Uploaded by

Manish Tomar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

History of C

In earlier days, every language was designed for some specific purpose.e.g FORRTRAN
(Formula Translator) was used for scientific and mathematical applications, COBOL
(Common Business Oriented Language) was used for business applications. So need of such
a language was felt which could withstand most of the purposes. From here the first step
towards C was put forward by Dennis Ritchie.

The C language was developed in 1970’s at Bell laboratories by Dennis Ritchie. Initially it
was designed for programming in the operating system called UNIX. After the advent of C,
the whole UNIX operating system was rewritten using it.

The C language is derived from the B language, which was written by Ken Thompson at
AT&T Bell laboratories. The B language was adopted from a language called BCPL(Basic
Combined Programming language), which was developed by Martin Richards at Cambridge
University.

In Short

C LanguageHistory

 Developed at Bell Laboratories. It’s first standard version released in 1972.


 Developed by Dennis Ritchie.
 Before c a Programming language is very popular in those days the name of the language is B-
Language so the developers decided the name of ‘C’ language because C is next to B.
C Language

C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972.C is a


basic structured programming language. In the late seventies C began to replace the more
familiar languages of that time like PL/I, ALGOL, etc.. Ritchie seems to have been rather
surprised that so many programmers preferred C to older languages like FORTRAN or PL/I, or
the newer ones like Pascal and APL.

Characteristics of C
 It is portable.
 It is simple and reliable.
 C is case sensitive.
 C is expandable.
 C is structured programming language.
 It is a high level language.

There are three types of languages-


1. High level language
2. Middle level language
3. Low level language

Note:
C is a high level language but has the capability of middle level language.

High level language


These are machine independent languages.it is easy to write and understand the programs of high
level languages.
To translate a program from high level language to low level language(so that it can be
understood by the machine) compiler or interpreter is used.
High level languages are further divided into two major categories.

1. Procedure Oriented language

In this category we are able to create our project or programs using procedural approach means
in this type we can able to divide our big project/program into small subroutines or procedures.
After making procedures we can able to call a ‘procedure’ one or more places.

The lists of procedural languages are as follows:

C language

C++ (Object Oriented)

Java (Objected Oriented)

Smalltalk (Objected Oriented)

Pascal language

2. Non-Procedural Languages: This category also known as ‘Problem Oriented languages’. In this
type of languages we can able to make program only at specific range like database. The
followings are the examples of Non procedural languages

1. SQL (Structured Query Language)


2. SNOBOL (String processor)

Low level language


Low level languages are machine language and assembly language.Machine language
understands only binary form(o and 1).Assembly level languages reduces the difficulties of
machine language and are in the form of English words like MOV,ADD,SUB etc…

Translators
The three types of translators are:-
 Assembler
 Compiler
 Interpreter

Assembler is used to convert the code of low level language into machine level language.
Compilers are used to convert the code of high level language to machine level language.

The working of Compilers and interpreters differ to each other-


Compiler convert the complete code at once but Interpreter does it line by line.

Keywords are the words whose meaning has already been explained to the C compiler (or in a broad
sense to the computer). The keywords cannot be used as variable names.

There are 32 keywords in C

auto double Int struct


break else Long switch
char enum resister typedef
case extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if Static while

The compilers of C are:-


 Turbo C
 Borland C++
 Dev IDE
 BCC Compiler in Linux/Unix
 Microsoft C
 Quick C
 Power C
 Lattice C

Common Short cut Keys Description

I. F2 press to Save current work

II. F3 press to open an existing file

III. ALT-F3 press to close current

IV. ALT-F9 press to compile only

V. ALT-F5 press to view the desired output of the program.

VI. CTRL-F9 press to compile+run


VII. ALT-X or ALT-F-X press to exit from TC IDE
VIII. Alt+x(quit the application)
IX. Shift+del(cut)
X. Ctrl+ins(copy)
XI. Shift+ins(paste)
XII. Ctrl+del(delete)
XIII. F5 – Full Screen and Restore
XIV. Alt+F5 – Output Window
XV. Alt+ windownumber – Switch among windows

 Header Files or Preprocessor Directives contains references or links of library functions. That is built-
in in the C language.

Suppose if you want to use a function clrscr() ; in the main function so must be declared on top #
include <conio.h> other wise you could have an prototype error.

Some header files are as follows

Stdio.h

Conio.h

Dos.h

String.h

Stdlib.h

- Library functions are provided along with the compiler inside special files called as header files
(.h)
o stdio.h – Standard Header File – printf(), scanf() etc.
o math.h – Mathematical functions – pow(), log() etc.
o conio.h – Console Input/Output – clrscr(), gotoxy(), textcolor(), textbackground() etc.

- We need to import the header files into our programs to use their library functions
- Use #include pre-processor directive to add the header files using any of two methods
o #include <filename.h>
o #include “filename.h”

Remember Some common rules for writing C program


 Use all commands or statements in lower or small case.
 ;
After completion of a statement excluding main() or loops must insert (semicolon) as a
statement terminator.
 Don’t use/declare identifier or variable name same as statement name suppose int include; this
is a wrong statement because include has a special meaning in the language.

Void main()

Every C programs consists of one or more functions. No matter how many

functions there are in a C program , main is the one to which control is passed

from the operating system when the program is run ; it is the first function

executed.

C character set

a. Alphabets
A,B,C……………..Y,Z

A,b,c,d,……………..x,y,z

b. Digits

0,1,2,3,4,5,6,7,8,9

c. Special characters

Writing first C program


# include<stdio.h>

Void main()

Printf(“hello to C”);

}
OR

# include ”stdio.h”

Void main()

Printf(“Hello to C”);

The output of this program is:-

Hello to C
Note:

Put the cursor inside function, keyword or header file and press Ctrl+F1(For help)

printf()

printf() is built-in function we can display with printf() any message, variable

value on screen/file/printer.

In printf() we can use many escape sequences and format specifies.

Escape sequences are special notations through which we can display our data

Variety of ways:

Some escape sequences and their functions are as follows:

Escape Sequence Description Example

\n Perform line feed & Carriage return operation printf("A\nB");

\t Prints a tab sequence on screen printf ("A\tb");


\’ Prints a single quote character on screen printf ("\’a\’");

\" Prints a double quote character on Screen printf ("\"a\"");

\r Perform carriage return operation printf ("a\rb")

\b Remove one character from left printf ("a\bHi!" );

Example Program #2

#include <stdio.h>

#include <conio.h>

void main()

clrscr();

printf( " \" I love india\" \n");

getch();

}
WHAT IS AN IDENTIFIER?

An identifier is used for any variable, function, data definition, etc. In the C programming
language, an identifier is a combination of alphanumeric characters, the first being a letter of the
alphabet or an underline, and the remaining being any letter of the alphabet, any numeric digit, or
the underline.

Two rules must be kept in mind when naming identifiers.


1. The case of alphabetic characters is significant. Using INDEX for a variable name is not
the same as using index and neither of them is the same as using InDeX for a variable
name. All three refer to different variables.
2. According to the ANSI-C standard, at least 31 significant characters can be used and will
be considered significant by a conforming ANSI-C compiler. If more than 31 are used, all
characters beyond the 31st may be ignored by any given compiler

Data types in C
- Special keyword defined by C language to specify the kind of data and amount of data
- Data types can be three types
o Primary Data Types
o Modified Data Types
o Derived Data Types
- Primary Data Types
o The data types that uniquely defines a type
 int – 2 or 4 bytes
 char – 1 byte
 float – 4 bytes – 6 dp
 double – 8 bytes – 14 dp
 void - nothing
- Modified Data Types
o The data types created by modifying the primary types using special keywords called
modifiers
 short
 long
 signed
 unsigned
o char
 signed char or char
 unsigned char - 0 to 255
o int
 unsigned int
 short int or short– 2 bytes
 long int or long – 4 bytes
 unsigned short int or unsigned short
 unsigned long int or unsigned long
o double
 long double – 10 bytes
- Derived Data Types/User Defined Data Types (UDT)
o Made of primary and modified data types
o Arrays, Structures, Unions, Bit fields, Enumerators etc.
Variables

- A name given to some position in memory to store and retrieve the data
- A variable name must have a data type associated with it

Syntax

datatype variable;

Example

char gender;

int empid;

double amount;

- A variable name must follow a set of rules


o Can have alphabets (a-z,A-Z) , digits (0-9) or underscore (_) only
o Can never start with a digit
o A variable name can be upto any length but first 32 characters are significant

Format Specifiers

- Special codes defined to format the data for input and output
- They starts with %
o %d – decimal
o %o – Octal
o %x or X – Hexa decimal
o %i – int
o %f – float
o %ld – long int
o %lf – double and long double
o %c – character
o %s – string without space
o %[^\n] - string with space
o %p – To show address in hexa
o %u - unsigned
- They are used with functions to input and output like printf(), cprintf(), sprintf(), scanf() etc.
o printf(“specifiers”,variable or value);
Example

int num=456;

printf(“Number in decimal is %d in octal is %o and in Hexa is %x”,num,num,num);

Assignment

- Convert degree Celsius to Fahrenheit for some value

Variable Vs Constants

- A variable can change its value anywhere anytime


o int num=6;
- Constant cannot change its value one assigned
o Can be made using
 Pre-processor directive called #define
 Using const keyword
o #define n 10
o const int m=10;

You might also like