Download presentation
Presentation is loading. Please wait.
Published byCharla Davis Modified over 9 years ago
1
C PROGRAMMING LECTURE C-language Computer Fundamentals
2
History of C C Evolved by Ritchie from two previous programming languages, BCPL and B Used to develop UNIX Used to write modern operating systems Hardware independent (portable) By late 1970's C had evolved to "traditional C"
3
History of C Standardization Many slight variations of C existed, and were incompatible Committee formed to create a "unambiguous, machine-independent" definition Standard created in 1989, updated in 1999
4
Language Types Three types of programming languages 1. Machine languages Strings of numbers giving machine specific instructions Example: +1300042774 +1400593419 +1200274027 2. Assembly languages English-like abbreviations representing elementary computer operations (translated via assemblers) Example: MOV AL, NUM1 ADD AL, NUM2 MOV VAL, AL
5
Language Types, Cont. 3. High-level languages Codes similar to everyday English Use mathematical notations (translated via compilers) Example: grossPay = basePay + overTimePay
6
High-level Languages “high-level” is a relative term C is a relatively low-level high-level language Pascal, Fortran, COBOL are typical high-level languages Java, Python, Perl, VB are examples of high-level high-level languages Application specific languages (Matlab, Javascript, VBScript) are even higher-level.
7
C Language C-language C is a high-level language. Writing a C code. {turbo C, DevC++} For DevC++ Compiling a C code. {F9} Compile & Execute. {F11}
8
Character Set of C-Langauge Alphabetic Letters A-Z A-z Numbers 0-9 Special Characters +,-,*,/,% {,},[,],”,, =,(,) etc C-language
9
Word Reserved Words Also called keyword Reserved for language and language has special meanings for these reserved word autoifbreak int case long Registercontinue returndefault short do sizeofdouble static else structswitch extern typedef float union dsignedfor unsigned goto whileenum void const Volatile char C-language
10
Words C-language User Defined Words User / Programmer defines(creates, declares) to solve his own problem Could variable, function, structure, class name int radius; radius is a reserved word char name[50]; Name is a reserved word
11
Variable Naming Rules Can’t be reserved word Must start with alphabetic letter or underscore only Must not contain any special character even space character is not allowed Not two variables can have same name within same scope C/C++ is case sensitive etc C-language
12
Codding Rules Every statement must end with semicolon Every program must have a main() function We place two statements on the same line; but they must be separated with semicolon Program must include respective header file if some required to be used in the program Variable naming rules etc C-language
13
Error Syntax Errors Due to violation of grammatical rules on language int first number;// invalid Logical Errors Due wrong use of logic or formula Area=3.14+radius+radius;// * must be there instead of + Run Time Errors Occur when specific condition meets Divide by zero C-language
14
My first C program! C-language #include using namespace std; // program prints hello world main() { cout<<"Hello world!"; } Output: Hello world!
15
Example 1 C-language #include using namespace std; // program prints a number of type int main() { int number = 4; cout<<“Number is”<< number; } Output: Number is 4
16
Example 2 C-language #include // program reads and prints the same thing int main() { int number ; cout<<“enter number: ”; cin>>number; cout<<“\nNumber is ”<< number; return 0; } Output : Enter a number: 4 Number is 4
17
more and more C-language #include using namespace std; int main() { /* this program adds two numbers */ int a = 4; //first number int b = 5; //second number int answer = 0; //result answer = a + b; }
18
Operators C-language OperatorsSymbols Increment Operators++ -- (Postfix), ++ -- (Prefix) Asthmatic Operators* / % + - Shift Operator > Relational Operators Bitwise Binary Operators & | ~ ^ Logical Operators&& || !
19
Some more Arithmetic Operators C-language Prefix Increment : ++a example: int a=5; b=++a; // value of b=6; a=6; Postfix Increment: a++ example int a=5; b=a++; //value of b=5; a=6;
20
Some more Data Types C-language
21
Contd… C-language Modulus (remainder): % example: 12%5 = 2; Assignment by addition: += example: int a=4; a+=1; //(means a=a+1) value of a becomes 5 Can use -, /, *, % also
22
Contd… C-language Comparision Operators:, =, !=, ==, !, &&, ||. example: int a=4, b=5; a<b returns a true(non zero number) value. Bitwise Operators: >, ~, &, |,^. example int a=8; a= a>>1; // value of a becomes 4
23
Operator Precedence C-language Meaning of a + b * c ? is a+(b*c) basically All operators have precedence over each other *, / have more precedence over +, -. If both *, / are used, associativity comes into picture. (more on this later) example : 5+4*3 = 5+12= 17.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.