CHAPTER 2 C Language
CHAPTER 2 C Language
Objectives
- a character is a single valid symbol available in the standard set of characters from ASCII table.
-Lexical elements are formed by combination of characters into tokens or syntactic units:
-identifiers
SYNTAX RULES
COMMENTS
-Arbitrary strings placed after symbol
// (Single-line comment)
Example: //This is an example
Or Between /* and */ (var-length comment)
Example: /* This is a comment
Using this sh*t */
KEYWORDS
-Words reserved for specific usage in C
Data Type Data Type Memory Class Control Structure, and Flow Makers/
Specifiers Modifiers Specifiers Special Operators Redirectors
char const auto if else
double enum ext ern switch case
float signed register for default
int struct static while do
long unsigned type def
break
short union
size of continue
signed volatile
go to
unsigned
run
void
IDENTIFIERS
-Strings used to have variables named constants, custom functions in the program.
-Should be chosen to aid easier understanding of source codes.
Examples of valid Identifiers:
x AN_IDENTIFIER
_id IsValid()
Counter1to61 This_is_an_identifier
LITERAL CONSTANTS
-combination of characters that are considered as literal values
Numbers
- Integers, Real numbers
Example: 2019, 54321.23
Character
Example: ‘A’ , ‘?’ , ‘ ‘ , ‘’
Strings
Example: “235”, “This is a string”, “/”Think Different”/”
Operators
Arithmetic operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Division – remainder
Assignment Operators
= (Simple) assignment {x + 3} is {x = x + 3}
+= Addition, assignment {x+=3} is x=x+3
-= Subtraction, assignment {x-=3} is {x=x-3}
*= Multiplication, assignment {x*=3} is {x=x*3}
/= Division, assignment {x/=3} is {x=x/3}
%= Modular Division, assignment {x%=3} is {x=x%3}
Comparison/Relational Operators
== Equality 5==5 (result to 1)
< less than 5<5 (result to 0)
> Greater than 5>4 (result to 1)
<= less than or equal 4<=5 (result to 0)
>= greater than or equal 4>=5 (result to 0)
!= Not equal 5!=5 (result to 0)
&& AND 1&&0 (result to 0)
|| OR 1||0 (result to 1)
! Not !0 (result to 1)
OPERATORS
Bitwise operator chapter 7
~ Tilde Unary Complement
& Ampersand AND
| Vertical Bar OR
^ Caret XOR
<< Double Less than sign Left Shift
>> Double Greater than sign Right Shift
>>= Bitwise right-shift assignment
<<= Bitwise left-shift assignment
&= Bitwise AND operation assignment
|= Bitwise OR operation, assignment
^= Bitwise XOR operation, assignment
Note: @exam, “anong klaseng operator ito?”
Special Operators
() Function call
[] Array Element Reference
- Direct member accessor
-> Indirect member accessor
?: Ternary member accessor
, Comma operator
Note: Might be in exam /
Punctuators
Symbol Use
() Grouping
{} Codeblock, (Array initial elements maker)
[] Array size marker
<> Standard header file indicator
; Statement terminator
// , /* */ Comment marker
# Preprocessor directive marker
‘ Variable or values separator
‘’ Character constants marker
“” String constant marker
% Output format marker
\ ……..Yen Escape character marker
: Label marker
More Lexical elements
-Expressions (Chapter 3)
-Clauses (Chapter 4)
-Function Headers (Chapter 5)
-Statements
-Preprocessor directives
-Declarations (chapter 3)
-variables (Chapter 3)
-functions (Chapter 5)
-Assignments (Chapter 3)
-Function calls (Chapter 5)
-Combinations
Labels
Example 2a: powers of 2
-a program that displays 6-digit power-of-two values starting from 2^0 to 2^10
//comments here
#include <stdio.h>
main () {
int i = 0
int power =1;
while (++i <=10)
printf(“%6d”, power*=2);
}
THE C SYSTEM
Language
-The grammar rules integrated with the compiler
Preprocessor
-Invoked when # is used in the preamble
-communicates with OS for preparing pre-compiler operations
Compiler
-converts source codes into machine instructions
Standard Library
-Pre-compiled functions saved in locations known by preprocessor
Header Files
Assert.h, ctype.h, errno.h, float.h, limits.h, math.h, setjmp.h, signal.h, stdarg.h,
stddef.h, stdio.h, stdlib.h