0% found this document useful (0 votes)
19 views12 pages

Unit 6 - Elements, Data Types, Consoles, and Operators

Uploaded by

Louise Cruz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views12 pages

Unit 6 - Elements, Data Types, Consoles, and Operators

Uploaded by

Louise Cruz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Elements and Data

types
Mark Kenneth Dionisio
Elements of a C Program
/* My first program in C */

Program Comments / Comments #include<stdio.h>


The characters /* and */ mark the start and end of the program #include<conio.h>
comment. Aswith any programming language, program comments are
used to put clarificatory notes within the program code, and are main()
ignored by the compiler. Program comments may be used anywhere in {
the program, and may be of any length. However, the programmer printf(“Hello World”);
should check that no part of the actual code is in between the /* and */ getch();
characters so that it will not be ignored by the compiler. In compilers
that support both C and C++, the double forward-slash (//) is also used Return 0;
for comments. The comments, however, extend only from the double }
slash at the end of the line. //end of program

2
Elements of a C Program
/* My first program in C */

Preprocessor directives #include<stdio.h>


This C program starts with #include <stdio.h>. This line is called a #include<conio.h>
preprocessor directive and it will include the "standard I/O library"
into your program. The standard I/O library lets you read input from main()
the keyboard (called "standard in"), write output to the screen (called {
"standard out"), process text files stored on the disk, and so on. It is an printf(“Hello World”);
extremely useful library. Another header file is the <conio.h>, which getch();
is used for screen handling functions. The getch() function located at
the bottom part of the program uses this header file. C has a large Return 0;
number of standard libraries like stdio, including string, time, and }
math libraries. A library is simply a package of code that someone else //end of program
has written to make your programming easier.

3
Elements of a C Program
/* My first program in C */

Main function #include<stdio.h>


The line main() declares the main function. Every C program must #include<conio.h>
have a function named main somewhere in the code. At run time,
program execution starts at the first line of the main function. main()
{
printf(“Hello World”);
getch();

Return 0;
}

//end of program

4
Elements of a C Program
/* My first program in C */

Curly braces #include<stdio.h>


In C, the { and } symbols mark the beginning and end of a block of #include<conio.h>
code. In this case, the block of code making up the main function
contains three lines. The first line (clrscr( );) is used to clear the main()
screen. {
printf(“Hello World”);
getch();

return 0;
}

//end of program

5
Elements of a C Program
/* My first program in C */

Display / Output function #include<stdio.h>


The printf statement in C allows you to send output to standard out #include<conio.h>
(for us, the screen). The text to be printed is enclosed in double-quotes
("This is the output of my first C program.\n"). The \n at the end of the main()
text tells the program to print a newline as part of the output. {
printf(“Hello World”);
getch();

return 0;
}

//end of program

6
Elements of a C Program
/* My first program in C */

Getch () function #include<stdio.h>


The getch( ) function; a line that reads a character from the keyboard #include<conio.h>
without echo on the on-screen and does not wait for carriage return.
More uses of getch( ) and other user inputs will be discussed later. main()
{
printf(“Hello World”);
getch();

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

You might also like