Upload
dodat
View
216
Download
0
Embed Size (px)
Citation preview
•Basic Programming Terminology i.e.
•Algorithms/Flowcharts etc.
•“HelloWorld” Program. i.e. using the ‘printf’ statement in C.
•Writing a program in ‘gedit’ and compiling it using the ‘gcc’ command in Ubuntu.
•Have attempted the Programming Assignment sent after the previous session !!
• How to name C Program Files !!
• C Program Memory Map
• Few techniques used during compilation.
• Using the ‘scanf’ statement to accept user input.
• Variables
• Keywords
• Data Types
• Operators
“HISTORY OF C”Developed by “Dennis Ritchie”
“Procedural” Programming Language
Actually developed for OS Programming.
Most Operating Systems(OS) are written in C and C++. eg. Windows, UNIX, Linux Kernel, etc.
HOW TO NAME C PROGRAM FILES
Most Important ---- extension ‘.c’
Few Rules/Conventions
All alphabets and numbers can be used.
Names should be in lowercase.
Can include underscores(_) or dashes(-).
• Program Code -- part of the memory where the written source code is stored, on execution.
• Stack -- linear type of memory, (“Last In First Out”) where local variables are stored.
• Heap -- unordered memory, i.e chunks of memory can be allocated without any order, where dynamic memory is allocated.
✦ Converting the source code (i.e code written in the programming language) into the target code (i.e. code understood by the computer)
✦ Using command gcc <filename>.c in the terminal.
-Wall optionThis command is used to enable and display all compiler warnings, in the source code.
These warnings are actually common programming errors, which do not affect the result of the program but are syntactically incorrect or unused memory blocks.
Very useful for beginners.
-o OptionThis command is used to specify the name of the output file; in case you wish to name it, rather than using the default name.After using this command, the program can run, simply by using this output filename. (i.e ./<filename>)
Data storage location in the computer’s memory.
When a program is loaded into the computer memory, we do not know which part of the memory is used to store our data.
Variables are used to refer to these parts, rather than remembering the actual memory address.
This data stored can be integers, real numbers, alphabets or special characters.
Hence comes the need for specifying “data-types”.
IDENTIFIERS
❖Variables have a “Name” ---- Identifier
❖To simplify, consider Variables as boxes and Identifiers as their labels.
RULES/CONVENTIONS IN NAMING VARIABLES
Variable Name can have alphabets, digits and underscores; but the first letter has to be an alphabet or underscore.
Length of Name can be up to 247 characters long.
Some reserved words (known as “Keywords”) cannot be used as Variable Names.
KEYWORDSReserved Words that convey special meaning to the compiler.Cannot be used as Variable Names.Typically, there are 32 keywords in C Programming Language.
• auto
• break
• case
• char
• const
• continue• default
• do
• double
• else
• enum
• extern
• float
• for
• goto
• if
• int
• long
• register
• return
• short
• signed
• sizeof
• static
• struct
• switch
• typedef
• union
• unsigned• void
• volatile
• while
LIST OF ALL KEYWORDS IN ‘C’
DATA TYPESAs mentioned earlier, data is of different forms, hence to differentiate between them, we need “Data Types”.
Five Basic Data Types in C :
int
char
float
double
void
Size of Data Types varies across Compilers and Processors.
However typically, char is 1-byte, int is 2-bytes, float is 4-bytes and double is 8-bytes.
HOW TO DECLARE VARIABLES
<data-type> <variable-name>;
Eg.
int rollno=23;
float percentage;
char grade= ‘A’;
Is there any difference between
eg. 1,2 and 3}
VARIABLE ASSIGNMENT STATEMENTS
• variable = expression/value;
• L-value or Location value appears on the LHS of the = sign. Denotes the address which is stored into.
• R-value or Read value appears on the THS of the = sign. Expressions produce the R-value.
• “All L-values are R-values, but not all R-values are L-values”.