main()
.main
.main
function, you may call other functions.#include <stdio.h>
./usr/include
and glibc
).main
function where execution begins when the program is run. This function is called main
.int main (void) { ... }
int main (int argc, char *argv[]) { ... }
int main (int argc, char *argv[], char *envp[])
Standard Headers you should know about:
stdio.h
– file and console (also a file) IO: perror
, printf
, open
, close
, read
, write
, scanf
, etc.stdlib.h
- common utility functions: malloc
, calloc
, strtol
, atoi
, etc.string.h
- string and byte manipulation: strlen
, strcpy
, strcat
, memcpy
, memset
, etc.ctype.h
– character types: isalnum
, isprint
, isupper
, tolower
, etc.errno.h
– defines errno
used for reporting system errors.math.h
– math functions: ceil
, exp
, floor
, sqrt
, etc.signal.h
– signal handling facility: raise
, signal
, etc.stdint.h
– standard integer: intN_t
, uintN_t
, etc.time.h
– time-related facility: asctime
, clock
, time_t
, etc./home/seed
).mkdir Cprograms
cd Cprograms
sudo gedit helloworld.c
helloworld.c
(.c
is an extension for all C files).Cprograms
folder.Cprograms
directory, in the terminal, browse to that directory.gcc –o helloworld helloworld.c
helloworld
name (this is an executable file)../helloworld
int fahr, celsius;
int lower, upper, step;
int
means that the variables listed are integers.float
- numbers that may have a fractional part.int
and float
depends on the machine you are using.int
and float
, including char
, double
, etc.int int1;
// declares an integer named int1double d;
// declares a doubleint1 = 5;
// int1 is given the value 5int int2 = 3;
// int2 is declared and initializedfloat x;
double d = 5;
int *p, i, a[100];
char s[21];
type variable_name, ... [= value];
int x, y, z;
x = 2;
x = x + 1;
y = z = 4 + 5;
x += 1;
++x; //Pre increment
x++; //Post increment
y = x--;
int i, j;
i = 1;
j = 1;
j = i++;