Professional Documents
Culture Documents
04 - C Programming
04 - C Programming
C Program
with Sir Beets
#include <stdio.h>
void main(){
Last Lecture // code inside
}
#include <stdio.h>
Preprocessor Directives
tells the preprocessor to
#define ROW 3
include the contents of
#define COL 4 the standard
input/output header
int signal; (<stdio.h>) in the program
int signal;
void main(){
int x=5, y;
scanf("%d", &y);
printf("%d", computeProduct(x, y));
}
#include <stdio.h>
The main() Function
#define ROW 3 Every C program has a
main() function with a
#define COL 4 declaration and
execution part.
int signal; Functions can return a
value and receive
information.
int computeProduct(int x, int y);
C Program
Structure void main(){
int x=5, y;
scanf("%d", &y);
printf("%d", computeProduct(x, y));
}
int signal;
scanf("%d", &y); 7
5
printf("%d", computeProduct(x, y));
}
x y
int computeProduct(int x, int y){
return x*y; 5 7
}
return-type function-name parameter-list
Function
Function Header int computeProduct(int x, int y){
return x*y; Function Body
}
scanf("%d", &y);
printf("%d", computeProduct(x, y));
}
#include<stdio.h>
Preprocessor Directives
#define c 10
#define d 20
C Program x = 5;
y = 4;
prod = x * y;
test();
void test()
{
printf("\n\nAll variables are accessed from the test function");
printf("\nValues: m=%d:n=%d:a=%d:b=%d", m, n, a, b); Function Definition
printf("\nc = %d; d = %d.\n", c, d);
}
You insert comments to document programs and improve program
readability. Comments do not cause the computer to perform any
action when the program is run—they’re ignored by the C compiler
and do not cause any machine-language object code to be
generated.
You can use /*...*/ multi-line comments in which everything from
Comments in /* on the first line to */ at the end of the last line is a comment.
C LANGUAGE 32 KEYWORDS
auto break case char
Variables
int width, height = 5; float area, side = 2;
width = 8; area = side * side;
Primary float
Used to declare variables that can take on
numeric values with a fractional part
Data Types Used for variables that can take on numeric
double values with a fractional part
Its size is more than float
Used to declare variables that can store one
char character as a value
Holds no value
void
Void type function: will not return any value
int i;
char c;
float f;
double d;
https://www.asciitable.com/
The fundamental raw material of any language used to represent
information, and useful to build computer programs.
Character Set Categories of the characters in C
1. Source Character Set
2. Execution Character Set
Alphabet: a-z and A-Z
Digits: 0,1,2,3,4,5,6,7,8,9
short int a;
long int b;
int main()
{
int x, y, ave;
x = 5;
y = 7;
Example ave = computeAverage(x,y);
// printf("%d",ave); do not print unless asked
return 0;
}