1.getting started with c
TRANSCRIPT
![Page 1: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/1.jpg)
Getting Started
What you’ll learn:
1. Basic Structure of a C Program
2. Basic Syntax of C language
3. Data Types
4. Defining Variables and Constants
5. Console I/O
![Page 2: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/2.jpg)
Getting Started
Basic Structure
![Page 3: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/3.jpg)
Basic Structure
A C program basically consists of the following parts:
Pre-processor Commands
Functions
Variables
Statements & Expressions
Comments
![Page 4: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/4.jpg)
Getting Started
Basic Syntax
![Page 5: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/5.jpg)
Character Set
Letters: A-Z a-z
Digits: 0-9
Symbols: + - * / % = _ | \ ~ ^ / ? ! @ # $ & : ; “ ‘ ` , . < > () {} []
ASCII symbols: 256 characters including the above ones.
Unicode symbols: UTF-8 can represent all 1,114,112 Unicode characters.
![Page 6: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/6.jpg)
Tokens
o Keywords
o Identifiers
o Literals
o Strings
o Punctuators
o Operators
![Page 7: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/7.jpg)
Keywords
32 Keywords from C89
auto double int struct break else long switch
case enum register typedef char extern return union
const float short unsigned continue for signed void
default goto sizeof volatile do if static while
5 Keywords from C99
_Bool _Imaginary
restrict _Complex
inline
6 Keywords from C11
_Alignas _Atomic
_Noreturn _Alignof
_Generic _Static_assert
![Page 8: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/8.jpg)
Identifiers
Rules for defining Identifiers
It can only contain letters, digits, or an underscore.
It should not start with a digit. It can start with a letter or an underscore.
A keyword should not be used as an identifier.
Since C is a case sensitive language so uppercase letters differ from lowercase ones.
Apple apple
![Page 9: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/9.jpg)
Valid and Invalid Identifiers
Valid Identifiers:-
VarName VAR2NAME _var11 var_name_11 int_100
Invalid identifiers:-
var-name 11varname int var name$var_name
![Page 10: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/10.jpg)
Literals
Literals are also called constants. We have following type of constants:
Integer constant 1, -11, 0xC, 010
Floating constant -32.56, 0.9787
Character constant ‘a’, ‘1’, ‘#’
![Page 11: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/11.jpg)
Strings
String literal is a sequence of characters.
E.g. “Hello”
It is terminated by ‘\0’.
E.g. “Hello” will be represented as “Hello\0” in memory.
![Page 12: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/12.jpg)
Punctuators
Square brackets [ ]
Parenthesis ( )
Curly Braces { }
Comma ,
Terminator ;
Colon :
Asterisk *
Ellipses …
Equal =
Pre-processor #
![Page 13: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/13.jpg)
Basic Operators used in C
Arithmetic: + - * / %
Assignment: = += -= *= /= %=
Increment/Decrement: ++ --
Relational: == <= >= < >
Logical: ! &&||
Conditional: ? :
and many more…
![Page 14: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/14.jpg)
Getting Started
Data Types
![Page 15: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/15.jpg)
Data Types
Fundamental int
float
double
char
void
Derived Arrays
Structure
many more ….
![Page 16: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/16.jpg)
For integer types
MODIFIERS SIZE RANGE
Int 4 bytes -2147483648 to 2147483647
Unsigned int 4 bytes 0 to 4294967295
Signed int 4 bytes -2147483648 to 2147483647
Short int 2 bytes -32768 to 32767
Unsigned short int 2 bytes 0 to 65535
Signed short int 2 bytes -32768 to 32767
Long int 4 bytes -2147483648 to 2147483647
Signed long int 4 bytes -2147483648 to 2147483647
Unsigned long int 4 bytes 0 to 4294967295
![Page 17: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/17.jpg)
For floating types
MODIFIERS SIZE RANGE
Float 4 bytes -3.4e-38 to +3.4e+38
Double 8 bytes -1.7e-308 to +1.7e+308
Long double 8 bytes -1.7e-308 to +1.7e+308
![Page 18: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/18.jpg)
For character types
MODIFIERS SIZE RANGE
Char 1 byte 0 to 255
Unsigned char 1 byte 0 to 255
Signed char 1 byte -128 to +127
![Page 19: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/19.jpg)
Getting Started
Variables and Constants
![Page 20: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/20.jpg)
Variables
It refers to a storage location in the memory space whose value can be manipulated.
int a = 10;
a = 20;
10
20
value at memory location
data type
identifier
valueof the variable
value changed
![Page 21: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/21.jpg)
Constants
It refers to a storage location in the memory space whose value is fixed.
const int a = 10;
a = 20;
10
10
value at memory location
data type
identifier
valueof the variable
value can’t be changed
keyword
![Page 22: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/22.jpg)
Getting Started
Console I/O
![Page 23: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/23.jpg)
Console Input Output
printf()
scanf()
![Page 24: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/24.jpg)
printf()
Used to display formatted output on the console.
Syntax:
printf(“Answer = %d”, i );
Format Specifier
Integer VariableFormatted Text
![Page 25: 1.getting started with c](https://reader036.vdocuments.us/reader036/viewer/2022062418/555e3658d8b42aad058b4884/html5/thumbnails/25.jpg)
scanf()
Used to take input from the console.
Syntax:
scanf(“%d”, &i );
Format Specifier
Integer VariableAddress of Operator