Академический Документы
Профессиональный Документы
Культура Документы
Programming
INTRODUCTION TO
PROGRAMMING
• C is machine independent
#include<conio.h>
Int main()
getch();
}
• Header files are the predefined files in the C library using
which we create new program
#include<conio.h>
int main()
getch();
}
Comments
• Comments are portions of the code ignored by the
compiler
– used to increase the readability of program for users
• Two types:
– Single line
// This is a C program single line comments example
// Welcome students in your course CP1103.
– Multiple line
/*
As you can see, you can include comments that can
occupy several lines also called multiple line
comment.
*/
/* TITLE :- MY FIRST C PROGRAM
CREATED BY :- XYZ */
#include<stdio.h>
#include<conio.h>
{
// to clear the output screen
printf(“My First C++ Program. \n”);
getch(); //to pause the final output
}
Include Directives and Namespaces
• include: directive copies that file into your
program
• namespace: a collection of names and their
definitions. Allows different namespaces to
use the same names without confusion
Tokens
• Tokens are the smallest individual unit of a
program in any language
– C tokens are:
• Special Symbols
• Words Symbols
• Identifiers
Reserved Words (Keywords)
• The syntax rules (or grammar) of C define
certain symbols to have a unique meaning
within a C program.
• There are 32 keywords in C and written in
lowercase. They can’t be used as variable.
• Reserved words, keywords, or word symbols
What is an Identifier?
• An identifier is the name to denote labels, types,
variables, constants or functions, in a C
program.
• C is a case-sensitive language.
– Work is not work
– Above example tells that “Work” is different variable
name and “work” is different variable, not same.
• Identifiers should be descriptive
– Using meaningful identifiers is a good programming
practice
Identifiers
• Identifiers must be unique
• Identifiers cannot be reserved words (keywords)
– double main return
• Identifier must start with a letter or underscore, and be
followed by zero or more letters (A-Z, a-z), digits (0-9),
or underscores
• VALID
age_of_dog _taxRateY2K
PrintHeading ageOfHorse
• NOT VALID
age# 2000TaxRate Age-Of-Dog main
What is a Variable?
• A variable is a memory address where data
can be stored and changed.
* multiplication
/ division
== Equal to 5 == 3 returns 0
> Greater than 5 > 3 returns 1
< Less than 5 < 3 returns 0
!= Not equal to 5 != 3 returns 1
>= Greater than or equal to 5 >= 3 returns 1
<= Less than or equal to 5 <= 3 return 0
Logical Operators
• An expression containing logical operator returns either 0 or 1
depending upon whether expression results true or false.
Logical operators are commonly used in decision making in c
programming.
Operator Meaning of Operator Example
If c = 5 and d = 2 then,
Logial AND. True only if all
&& expression ((c == 5) && (d
operands are true
> 5)) equals to 0.
If c = 5 and d = 2 then,
Logical OR. True only if
|| expression ((c == 5) || (d
either one operand is true
> 5)) equals to 1.
Logical NOT. True only if If c = 5 then, expression !
!
the operand is 0 (c == 5) equals to 0.
Assignment Operator
• An operator to give (assign) a value to a
variable.
• Denote as ‘=‘
• Only variable can be on the left side.
• An expression is on the right side.
• Variables keep their assigned values until
changed by another assignment statement or
by reading in a new value.
Assignment Operator Syntax
• Variable = Expression
– First, expression on right is evaluated.
– Then the resulting value is stored in the memory location of Variable on left.
– “ = “ is commonly used but there also have some other operators.
= a=b a=b
+= a += b a = a+b
-= a -= b a = a-b
*= a *= b a = a*b
/= a /= b a = a/b
%= a %= b a = a%b
Bitwise Operators
• During computation, mathematical operations like: addition, subtraction,
addition and division are converted to bit-level which makes processing
faster and saves power.
• Bitwise operators are used in C programming to perform bit-level
operations.