Você está na página 1de 7

BCPL (Martin Richard, 1967), B (Ken Thompson, 1970) The C programming language was designed by Dennis Ritchie at Bell

l Laboratories in the early 1970s

#include<stdio.h> int main() { .

prog1.c

compiles
Syntax Errors? No Object machine code
prog1.obj

Yes

Executable machine code


prog1.exe

Runtime or Logic Errors ?

Yes

Output
Translators are system software used to convert high-level language program into machine-language code.

Compiler : Coverts the entire source program at a time into object code file, and saves it in secondary storage permanently. The same object machine code file will be executed several times, whenever needed. ( Compiler check the whole program at time) Interpreter : Each statement of source program is translated into machine code and executed immediately. Translation and execution of each and every statement is repeated till the end of the program. No object code is saved. Translation is repeated for every execution of the source program. ( interpreter checks the program line by line) Note: Compilers takes much time to compile and less time execute a program where as interpreter less time to compile and much time to execute a program. C Features 1. 2. 3. 4. 5. Rules : 1. 2. 3. 4. C is case sensitive /**/ are used as comment lines. all variable should be declared by its data type. all statements shall be terminated by semicolon (;). C is middle level language which supports machine and high level language Built-in Functions Capability to extend itself. 32 keywords are there to help users Structured programming language.

Character Set of C-Language Alphabets : A-Z and a-z Digits : 0-9 Special Symbols :~!@#$%^&()_-+=|\{}[]:;<>,.?/ White Spaces : space , Horizontal tab, Vertical tab, New Line,Form Feed. C-Language Keywords:auto break case char const continue default double else enum extern float for goto int long register return short signed sizeof struct switch typedef union unsigned void volatile

do

if

static

while

Key words : have a predefined meaning and these meanings cannot be changed. All keywords must be written in small letters . Identifiers : names of variables, functions, structures, unions, macros, labels, arrays etc., Variable : A variable is name which is used to represents the data at the time of program execution. Note : a variable must be declared with its data type Ex : int a ; Char name[10]; Rules for define variable : a) First character must be alphabetic character or under score b) Second character onwards alphabetic character of digit or under score. c) Cannot duplicate a key word. d) May not have a space or any other special symbol except under score. e) C language is Case-sensitive.

Type char unsigned char signed char int unsigned int signed int short int unsigned short int signed short int long int unsigned long int signed long int float

Typical Size in Bits 8 8 8 16 16 16 16 16 16 32 32 32 32

Minimal Range 0 to 255 127 to 127

0 to 65,535 32,767 to 32,767 0 to 65,535 32,767 to 32,767 0 to 4,294,967,295 2,147,483,647 to 2,147,483,647 3.4e-38 to 3.4e+38

double long double

64 80

1.7e-308 to 1.7e+308 3.4e-4932 to 1.1e+4932

Conversion Specifiers
Code %s %c %d %f %e %g %u %o %x %i %p %n %hd %ld %lf %%
printf (); This function is used to print output data on the screen. (Writes formatted data to screen) Syntax : printf(formatted string, variable);

Format String of characters (until null zero is reached ) Character Decimal integer Floating-point numbers Exponential notation floating-point numbers Use the shorter of %f or %e Unsigned integer Octal integer Hexadecimal integer Signed decimal integer Display a pointer The associated argument must be a pointer to integer, This sepecifier causes the number of characters written in to be stored in that integer. short integer long integer long double Prints a percent sign (%)

Basic Structure of a C Program documentation section preprocessor directives global declaration section main() { local declarations; input statements; processing statements; output statements; } user-defined function definitions;

Variables A variable is an identifier that represents a value. The value represented by the identifier may be changed during the execution of the program. Variable names must be a valid identifier. Declaration of a variable: General form: Example: int i, j, k; float x, y, z; char ch; Data_type list variables; CONSTANTS A constant refers to the fixed values that do not change during the execution of a program There are two types of constants. Symbolic constants Constant variables, also called read-only variables SYMBOLIC CONSTANTS A symbolic constant is defined in the preprocessor area of the program and is valid throughout the entire program The preprocessor directive #define is used to define symbolic constants in a program. Example: #define SIZE 10 #define PI 3.14 A constant variable is declared and initialized in the variable declaration section of the program and cannot be modified thereafter. Keyword const is used to declare constant variables. Example:

const int size = 100; const float pi =3.14; const char ch = a; CONSTANT CONSTANTS OPERATORS Types of operators: Arithmetic Relational Logical Increment / Decrement Bitwise Ternary Special ARITHMETIC OPERATORS The following are the arithmetic operators of C: Arithmetic Operators Description + Addition - Subtraction * Multiplication / Division (Second operand must be nonzero) % Modulus (Both operands must be integer and second operand must be non zero) RELATIONAL OPERATORS Following are the relational operator of C Relational Operators Description < Less than <= Less than or equals to > Greater than >= Greater than or equals to == Equals to != Not equals to LOGICAL OPERATORS Following are the logical operators of C: Logical Operators Description && Logical AND (True only if both the operands are true) || Logical OR (True if either one operand is true) ! Logical NOT (Negate the operand) Assignment Operators The following are the assignment operators of C: Assignment Operators Description = Assignment operator which assign a value to an identifier

+=, *=, -=, /=, %= Compound assignment operators Example : a=a+b is equivalent to a+=b INCREMENT AND DECREMENT OPERATORS 1) ++: Pre increment or post increment. For example:++k refers pre increment whereas k++ refers post increment. 2) --: Pre decrement or post decrement. For example:--k refers pre decrement whereas krefers post increment. TERNARY AND UNARY OPERATORS 1) Ternary ?: - Used to carry out simple conditional checking. Example: big=( a>b )?a : b; BITWISE OPERATORS Bitwise Operators Description & Bit wise AND | Bit wise OR << Left shift >> Right Shift

Você também pode gostar