Professional Documents
Culture Documents
Outline:
C programming Constants and Variables
C Programming Data Types
C programming Comments
Variables:
In this lesson, you will learn about basic data types such as int , float, char etc. in C
programming.
Data Type Size Description
Integers is the set of numbers that include all the whole numbers
and their negative values.
The set of integers can be represented as -∞ .... -5, -4, -3, -2, -1,
0, 1, 2, 3, 4, 5.....∞
In programming, integer is a data type used to represent integer
values. We can declare a variable as an integer type or define the
result of a function or expression as of integer type.
A variable declared as an integer type occupies a specified
amount of memory space in computer. The amount of space
occupied depends on the computer system you are using –
typicall ranging from 4 bytes to over 64 bytes.
A variable defined as an integer type cannot store any other
types of data such as character like a,b,c or floating-point
numbers like 5.43, -0.43.
Integer(con..)
Example:1
#include<stdio.h>
#include<math.h>
int main()
{
float x=2.13;
printf("The output of X=%f",x);
return 0;
}
Floating-point(con…)
Example:2
#include<stdio.h>
#include<math.h>
int main()
{
float x;
printf("Enter a Float Number:");
scanf("%f",&x);
printf("The output of X=%f",x);
getch();
return 0;
}
Character
Character is a symbol in programming language that has meaning.
A character can be any letter, number, punctuation marks, symbols or
whitespace. For example, the word "character" consists of eight
characters, and the phrase "Hello World!" consists of 12 characters
including the whitespace and exclamation mark.
In programming character is a datatype. We can declare a variable as of a
character type and store characters in the variable. For example, in C , we
write,
char first = 'a';
Characters when storing in a variable must be inserted between single
quotes.
String is another datatype in programming, which is a modified version of
character datatype. Strings are used to store more than one characters.
Character(con…)
Example:1
#include<stdio.h>
int main()
{
char b='A';
printf("The Output of B is Equal to:%c",b);
return 0;
}
Character(con…)
Example:2
#include<stdio.h>
int main()
{
char a;
printf("Enter a Character:");
scanf("%c",&a);
printf("The Output of Variable A is Equal to:%c",a);
return 0;
}
Character(con…)
Example:3
#include<stdio.h>
int main()
{
char str[]="farah";