Академический Документы
Профессиональный Документы
Культура Документы
Welcome to C
Welcome to C
Compilers and Interpreters
The Hello World program
Comments in C
Bugs and Programs
CIRCLE.C-A Small C Program
Use of Whitespace in C
Constants in C
[1]
Why C?
C is the common
Originated at AT&T Bell Labs,
denominator of many of Dennis Ritchie – implemented
today’s languages 1972
Getting Started
[2]
C Standard Library
[3]
The C Programming Process
Compilation
the outputs
Test your solution
Code your solution Preprocessed
C Source Program
Compile Edit your
program
Handling errors
C Object
Run and Test your File
Executable
program File
[4]
Before and after Compilation
[5]
Getting Started
Compilation and Linking
[6]
Interpreters
output from
Getting Started
interpreter
program
MYPROG.C
• No object code and executable files created.
• Slower execution as interpreter has to translate
high level language and then execute the
command.
[7]
The Smallest C Program
MINIMAL.C
Getting Started
main( )
{
}
[8]
The Hello World Program
#include <stdio.h>
main()
{
Getting Started
printf("Hello,world!\n");
}
Compile and run the above program on your computer. You may get a
warning from the compiler saying "Function must return a value". For
the time being, we will ignore the warning and focus on the following
output of the program which will be displayed on the monitor of your
computer.
[9]
Studying an outline
#include <stdio.h>
“#” read as “hash”
A function
Getting Started
(procedure) main()
{ Preprocessor Directives
name
… Code (# commands) go here
… goes
… here
}
A block … Multiple functions and
… blocks are optional
… depending on the program’s
requirements
[10]
Studying a Program
[11]
Arguments of a Function
"Chop what?"
The answer to this question make up the
arguments to the function which are placed
inside a set of parentheses after the name of the
function For example:
chop(onions);
chop(beans);
[12]
Studying a Program
[13]
Studying a Program
ARGUMENTS("Hello, World!");
[14]
Studying a Program
[15]
The Header Files
#include <stdio.h>
[16]
Preprocessor Directives
#include <stdio.h>
main()
{ …
begin with a hash sign (#) - Never put a semicolon
at the end of the preprocessor directives because
they are pre-processor commands and not C
commands
[17]
Preprocessor Directives
[18]
A Typical Compiler Installation
bin sub directory - contains all programs like
compilers, debuggers, etc. (*.exe files)
include subdirectory - contains all library header files
Getting Started
(*.h files)
lib subdirectory - contains object code of all library
functions. (*.lib, *.olb, *.obj files)
other subdirectories may contain other files (help,
examples, etc.).
Most C compilers are also C++ compilers!!
(compilation depends on file extensions)
.c for C files
.cpp for C++ files
[19]
Comments in C
Readability is IMPORTANT
Use Comments to explain what’s going on to yourself
Getting Started
[20]
HELLO2.C
/*============================== HELLO2.C =====================
Introductory program from "The C Programming Language"
by Kernighan and Ritchie (2nd. ed.) PHI
Getting Started
=============================================================*
/
#include <stdio.h>
int main() /* start of main */
{
printf("Hello,world!\n");
printf("Good morning!");
WHAT WILL THIS DO ??????
return 0;
} /* end of main */
[21]
Bugs and Programs
[22]
CIRCLE.C - A Small C Program
Getting Started
Don’t Worry
Just watch it like a movie trailer !!!!!!!!!!!!!!!!!!
[23]
CIRCLE.C - A Small C Program
/*============================== CIRCLE.C =======================
Program to calculate the area of a circle.
=============================================================*/
#include <stdio.h>
Getting Started
#define PI 3.141592
int main() /* start of main */
{
float radius, area; /* variable declaration */
float find_area(float); /* function declaration */
printf("\n\nEnter radius >> "); /* output statement */
scanf("%f",&radius); /* input statement*/
if(radius < 0) /* input validation */
{
/* action on error */
printf("\nERROR: Radius must be non-negative");
}
[24]
CIRCLE.C - A Small C Program
else
{
area = find_area(radius); /* call to function */
Getting Started
[25]
Use of Whitespace in C
Spaces, tabs, blank lines, formfeed characters (special
characters which tell printers to move to the next sheet),
and carriage returns are known as whitespace characters.
Getting Started
[26]
Constants in C
NUMERIC CONSTANTS
Integer Constants (e.g., 45, -567)
Getting Started
[27]
Points to Remember
Compilers and interpreters are two ways to execute a
program.
A C program needs to compiled and linked before it
Getting Started
[28]
Bon Voyage
WELCOME ABOARD!
YOUR EXCITING JOURNEY
INTO THE MYSTERIES OF 'C'
PROGRAMMING HAS JUST
BEGUN !!!
[29]