0% found this document useful (0 votes)
33 views31 pages

An Over View of C Programming

Uploaded by

Raghu M E
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views31 pages

An Over View of C Programming

Uploaded by

Raghu M E
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

An Over View of C

programming
Raghu M E
Associate Professor
Department of CSE
Government Engineering College, Hassan
Contents

• Computer and its Components.


• Need for programming Languages.
• Types of programming Languages.
• An over View of C programming.
History
• 1950's
• Large devices, accessible to few people
• 1960's • 2000's
• Commercial usage emerges • Computers are even fast, laptop, super
• Operated by experts computers,….

• 1970's • Owned and used by …………


• Computers cheaper, smaller
• 1990's
• Computers fast, small, inexpensive, Owned and used by many people
Elements of a Computer System
Hardware
CPU
• The "brain" of the
• Keyboard
computer
• Disk drive
• Scanner
• Mouse

• Hard Disk
• Screen
• Disk Main Memory
• Printer
• CD-Rom/ DVD • Data and
• Plotter
instructions stored
• Tape Backup to, fetched from
Elements of a Computer System
Software

• Systems programs
• Control the computer
• Includes Operating System
• Applications programs
• Word processors
• Compilers
• Spreadsheets
• Data Bases
Need for Computer Languages

• For solution to problems.


• Which are solvable.
Must be:
• User friendly.
• Portable and flexible.
• Easy to understand.
• Must have syntax.
Types of Languages

• Machine Level –
Binary Data ( 0’s and 1’s )
• Assembly Level –
Instructions (Need translators)-LDA, ADD, etc..
• High Level –
English like Statements (Need translators)
Processing a High-Level Language Program

Fig: Conversion of high level language to machine level


Structured Programming
• Thoroughly understand the problem
• Determine
• the output desired
• the required input
• processing that will occur
• Divide the problem into sub-problems

• Other names for this process


• structured design
• top-down design
• stepwise refinement
• modular programming
C programming

• Currently, the most commonly-used language for embedded systems


• “High-level assembly”
• Very portable: compilers exist for virtually every processor
• Easy-to-understand compilation
• Produces efficient code
• Fairly concise
Cont.…

• Developed between 1969 and 1973 along with Unix


• Due mostly to Dennis Ritchie
• Designed for systems programming
• Operating systems
• Utility programs
• Compilers
• Filters
• Evolved from B, which evolved from BCPL
Cont.…

• Character set
• Keywords
• Data types
• Constants
• Identifiers
• Variables
• Strings
Cont.…

• Types of symbols
• Read/write statements
• Conditional / control statements
• Arrays
• Strings
• Functions
• Structures / Unions
• Pointers
• Files
• Memory allocation
Cont.…

C programme structure
/*documentation*/
main( )
{

Body
}
Cont.…

{
Declarations;

Statements;
}
Cont.…

#include <stdio.h> Preprocessor used to share


information among source
files
+ Cheaply implemented
void main()
+ Very flexible
{
printf(“Hello, world!\n”); Program mostly a collection of
} functions
“main” function special: the
entry point
I/O performed by a library
function: not included in the “void” qualifier indicates
language function does not return
anything
Pieces of C

• Types and Variables


• Definitions of data in memory
• Expressions
• Arithmetic, logical, and assignment operators in an infix notation
• Statements
• Sequences of conditional, iteration, and branching instructions
• Functions
• Groups of statements and variables invoked recursively
C Expression Classes
• arithmetic: + – * / %
• comparison: == != < <= > >=
• bitwise logical: & | ^ ~
• shifting: << >>
• lazy logical: && || !
• conditional: ? :
• assignment: = += -=
• increment/decrement: ++ --
• sequencing: ,
• pointer: * -> & []
Conditional statements

• If and its variants


• Switch
• goto
Control statements/ looping

• For - for(initialization; condition; increment/ decrement) { body }


• While – while(condition) { body}
• Do…….while – do { body} while (condition);

• Entry controlled
• Exit controlled
Arrays
• Array: sequence of identical objects in memory
• int a[10]; means space for ten integers
• By itself, a is the address of the first integer
• *a and a[0] mean the same thing
• The address of a is not stored in memory: the compiler inserts code to
compute it when it appears
Multidimensional Arrays

• Array declarations read right-to-left


• int a[10][3][2];
• “an array of ten arrays of three arrays of two ints”
• In memory
Functions
int gcd(int m, int n)
{
int r; #include<stdio.h>
while ( (r = m % n) != 0) { void main( )
m = n; {
n = r; High-level control-flow int n
} statement. Ultimately
returnEach
n; function becomes a conditional n=gcd( 5,10);
branch.
} returns a single
value, usually an Supports “structured printf(“%d”,n);
integer. Returned programming” }
through a specific
register by
convention.
Strings

• Char array - char str[20];


• String length, vowels and consonants count, substring,
conversion, copy, concatenation
• Built in function available
Eg:- strlen( ), strcnt( ), strcpy ( ), strcmp( ), strcat ( ) etc ….
Structure and Union

• Different data types in single name.


• struct tagname { } structure name;
• Union – memory is common.
Pointers
• Holds address of variable.
• Symbols: *, &
• int * p;
• Declaration and Initialization
• Can used with any data types.
• Memory allocation - dynamically
Files

• Collection of records.
• Binary and text files.
• File pointer.
• File open, close.
• Read, write, append modes.
Memory allocation

• Static and dynamic


• Dynamic
malloc ( )
calloc ( )
realloc ( )
free ( )
The Main Points

• Like a high-level assembly language


• Array-of-cells model of memory
• Very efficient code generation follows from close semantic
match
• Language lets you do just about everything
• Very easy to make mistakes
Thank you
Questions?

You might also like