Programming Languages Unit - I
Programming Languages Unit - I
All the words in a program line must be separated from each other
by at least one space, or a tab, or a punctuation mark.
All variables must be declared for their types before they are used
in the program.
• C Character Set :
• C uses the uppercase letters A to Z, the
lowercase letters a to z, the digits 0 to 9, and
certain special characters
Character Name
, comma
. period
; semicolon
: colon
? question mark
‘ apostrophe
| vertical bar
/ slash
\ backslash
Character Name
& ampersand
^ caret
* asterisk
- minus sign
+ plus sign
= assignment sign
< opening angle bracket or
> closing angle bracket or
Character Name
( left parenthesis
) right parenthesis
[ left bracket
] right bracket
{ left brace
} right brace
• Constants and Variables
• Variables
• A quantity whose value changes during the
execution of the program is called a variable.
• C variable refers to the name given to the memory
location to store data.
• A Variable name is formed with alphabets, digits
and a special character underscore (_).
• The following are some valid variable names
AD,BASIC_PAY ,volume, B12
• The following are some invalid variable names AB. ,
9A
• Program to Display "Hello, World!“
#include <stdio.h>
int main()
{
printf("Hello, World!");
}
Output:
Hello, World!
• Constants
• A Constant is a quantity whose value does not
change during program execution.
• Keywords and Identifiers
• Every C word is classified as either a keyword
or an identifier. All keywords have fixed
meanings and these meanings can not be
changed.
• float
• goto
• int
• char
• Expressions :
• An expression is a formula for computing a
value.
• It is a combination of operands and
operators arranged as per the syntax of the
language.
Arithmetic expressions - contains only arithmetic
operators and operands. ex: x+z
Relational expressions – connecting constants or
variable or arithmetic expression by relation operator
It is used to find out the relationship between two
operands.
Ex : A*A-B > C*C-D
Logical expressions – formed by connecting
expressions by logical operator. The value of expression
is either True or False.
Conditional expressions – It returns one value if
condition is True & returns another value if condition is
false
• The main ( ) function
• Every executable program must contain a
special function called main (), which is where
the program execution begins.
• Unformatted I/O Function
• we have functions for performing I/O of one
character at a time, known as character I/O
functions
• getchar ()
• Formatted I/O Functions :
• scanf ( ) Function – Formatted Input
function
• scanf( "%d", &b );
• Code Meaning
• %c read a single character
• %d read a decimal integer
• %f read a floating point value
• printf ( ) Function – Formatted Output
function