a very basic c lecture
TRANSCRIPT
-
8/4/2019 A Very Basic c Lecture
1/30
A VERY BASIC C LECTURE
Welcome to CODING CLUB
-
8/4/2019 A Very Basic c Lecture
2/30
WHAT WE WILL COVER
What is computer ?
What is computer architecture ?
What is HLL ?
What is compiler ?
What is C ?
What is C compiler ?
IDEs
What if I want more ?
-
8/4/2019 A Very Basic c Lecture
3/30
WHAT IS COMPUTER
A machine that can carry out set of
instructions
It understands only binary language.
But can it really understand ?
Answer - No.
-
8/4/2019 A Very Basic c Lecture
4/30
Computer can process binary stuff in the
sense that it has components that can
compare voltages and tell difference between
high and low voltage.
But COUNTER STRIKE is no binary
That is because we attach certain meanings to
the binary data.
-
8/4/2019 A Very Basic c Lecture
5/30
PROCESSING WHAT ON EARTH IS THAT ?
Running a given instruction to solve a specificpurpose.
What purpose ? And how ?
Say for instance . ADDITION.
4 = 100 in binary. ( 1x2^2 + 0x2^1 + 0x2^0)
5 = 101 in binary. ( 1x2^2 + 0x2^1 + 1x2^0)
Ask computer to solve 4+5
-
8/4/2019 A Very Basic c Lecture
6/30
-
8/4/2019 A Very Basic c Lecture
7/30
-
8/4/2019 A Very Basic c Lecture
8/30
COMPUTER ARCHITECTURE
THE BUILDING BLOCKS .
-
8/4/2019 A Very Basic c Lecture
9/30
COMPUTER ARCHITECTURE
The rules that we showed you make up the
computer architecture. At the core , every
computer is the same (except quantum
computers) , but how you combine those basicfunctions is what makes all the difference.
-
8/4/2019 A Very Basic c Lecture
10/30
COMPUTER ARCHITECTURE
So what architectures are available out there ?
INTEL x86 - eg. Pentium, Core2Duo .
INTEL x64 eg Pentium64 , i3 , i5 , i7
AMD x86 Turion , Athlon
AMD amd64 athlon64 , X3 etc .
Sun SPARC eg. ultraSPARC processors.
RISC processors .
And a host of others.
And binary for one architecture wont (usually) work on another
( In the sense that it isnt supposed to work. )
-
8/4/2019 A Very Basic c Lecture
11/30
HIGH LEVEL LANGUAGE
What is it ?A nomenclature where the machine code is namedsomething that makes direct sense to us. Likevariables , strings , integers , operators + , - etc.
Why do we need it ?
1. We cant program in binary.
2. We wont love to program in assembly.3. We have many other interesting things to do than
trying to add and subtract.
-
8/4/2019 A Very Basic c Lecture
12/30
WHAT IS A COMPILER ?
A program that converts a high level language intoits binary equivalent (given you provide thearchitecture) .
High level code (architecture independent)
A = b + c
ToAssembly (architecture dependent)
Add $r1 , $r2 , $r3
ToMachine code the executable (architecture dependent)
00100 000000000000 00001 00010 00011
-
8/4/2019 A Very Basic c Lecture
13/30
But wait !!!
Wasnt this supposed to be a C lecture ???
It was and it still is.
Just that you cannot feel C without this basicknowledge.
-
8/4/2019 A Very Basic c Lecture
14/30
WHAT IS C ???
A high level language that was developed in
late 1960s by DENNIS RITCHIE.
Has become very famous since then for its
simplicity and efficiency.
Has inspired many other languages directly or
indirectly . Like C++ , python , java.
-
8/4/2019 A Very Basic c Lecture
15/30
SYNTAX
Every statement ends with a semicolon.
int a , b ,c ;a = b + c ;printf( this is a string ) ;
-
8/4/2019 A Very Basic c Lecture
16/30
SYNTAX
Blocks of code are to be enclosed within curly
braces
if ( this_value > 100 )
{Statement1; // comments here
Statement2; //comments here
}
-
8/4/2019 A Very Basic c Lecture
17/30
OPERATORS
C supports all the real life operators . Like
+ , - , / , * , > , < ,= etc .Where each as the normal meaning.
It also has a few shortcuts like incrementing a variable .
a = a + 1; // new value of a = current value of a + 1
Can be written in short as
a++;
-
8/4/2019 A Very Basic c Lecture
18/30
-
8/4/2019 A Very Basic c Lecture
19/30
LOOPING
The for loop . Iterates a code for given number oftimes.
int i;
for ( i = 0 ; i < 10 ; i++){printf(%d , i);
}
This code prints 0 1 2 3 4 5 5 7 8 9
-
8/4/2019 A Very Basic c Lecture
20/30
VARIABLES
Declaring variablesint a ; //an integer a
float x; //a fraction ie floating point variable x
float y; assigning variables values
a = 100;
x = 4.11;
y = x/a;// float divided by int is a float find out why.
-
8/4/2019 A Very Basic c Lecture
21/30
ARRAY OF VARIABLES
Declaration
int a[10]; // an array of size 10
//please note that this corresponds to
// index values 0 to 9.
Assigning values
a[4] = 10; //assign the fifth element of array value 10
-
8/4/2019 A Very Basic c Lecture
22/30
FUNCTIONS
Functions are blocks of code you can call from otherfunctions.
Like real life sine function can be represented as
float sine( float x)
{
// Procedure to calculate sine of xreturn // the value
}
-
8/4/2019 A Very Basic c Lecture
23/30
This is how it works ..
You call sine function and pass variable x to It as anargument. It uses this variable to calculate the function value
and returns you the result
Just like in real life you write
y = sine(x)
In C you can write
some_variable_y = sine( some_variable_x);
-
8/4/2019 A Very Basic c Lecture
24/30
LIBRARIES
These are commonly used codes that have beenwritten beforehand for your use.
Eg.
Library stdio.hprintf(some string);
scanf(%s , &some_character_array);
// please note that & before the character arrayname is must something you will understandwhen you delve deeper.
-
8/4/2019 A Very Basic c Lecture
25/30
-
8/4/2019 A Very Basic c Lecture
26/30
-
8/4/2019 A Very Basic c Lecture
27/30
COMPILATION
I am using the gcc compiler its pretty easy to
use in linux. Not so in windows.
You will definitely need an ide in windows.
I personally like CODEBLOCKS for C and C++
programming
There are others like DEV-C++ , VISUAL-C++
etc
-
8/4/2019 A Very Basic c Lecture
28/30
INTEGRATED DEVELOPMENT ENVIRONMENT
-
8/4/2019 A Very Basic c Lecture
29/30
-
8/4/2019 A Very Basic c Lecture
30/30
WHERE DO I GO FOR MORE ???
First of all.
Wikipedia
Then refer some other top sites on google search
When you search C TUTORIALS