Unit 6 - Elements, Data Types, Consoles, and Operators
Unit 6 - Elements, Data Types, Consoles, and Operators
types
Mark Kenneth Dionisio
Elements of a C Program
/* My first program in C */
2
Elements of a C Program
/* My first program in C */
3
Elements of a C Program
/* My first program in C */
Return 0;
}
//end of program
4
Elements of a C Program
/* My first program in C */
return 0;
}
//end of program
5
Elements of a C Program
/* My first program in C */
return 0;
}
//end of program
6
Elements of a C Program
/* My first program in C */
return 0;
}
//end of program
7
Elements of a C Program
/* My first program in C */
return 0; #include<stdio.h>
#include<conio.h>
Terminates the main() function and returns the value 0.
main()
{
printf(“Hello World”);
getch();
return 0;
}
//end of program
8
Elements of a C Program
/* My first program in C */
Semicolons #include<stdio.h>
In a C program, the semicolon is a statement terminator. That is, each #include<conio.h>
individual statement must be ended with a semicolon. It indicates the
end of one logical entity. main()
{
printf(“Hello World”);
getch();
return 0;
}
//end of program
9
Data Types and Variables
Data Types
#include<stdio.h>
#include<conio.h>
main()
{ clrscr();
int FirstNumber;
printf(“Hello World”);
scanf(“%d”, &FirstNumber);
printf(“Your chosen number is %d, FirstNumber);
return 0;
}
//end of program
Data Types and Variables
Variables
In C, a variable must be declared before it can be
used. Variables can be declared at the start of any
#include<stdio.h> block of code, but most are found at the start of
#include<conio.h> each function. Most local variables are created
main()
when the function is called, and are destroyed on
{ clrscr(); return from that
int FirstNumber; function.
printf(“Enter first number”);
scanf(“%d”, &FirstNumber);
printf(“Your chosen number is %d, FirstNumber);
return 0;
}
//end of program
Data Types and Variables
#include<stdio.h>
#include<conio.h>
main()
{ clrscr();
int FirstNumber;
printf(“Hello World”);
scanf(“%d”, &FirstNumber);
printf(“Your chosen number is %d, FirstNumber);
return 0;
}
//end of program