Comparing C with Java (relating to what you have learned)
 

Things you find in a Java program:

Statements are (always) inside a method !!!

Comparing C with Java (relating to what you have learned)
 

Important property of Object Oriented Programming (OOP) Languages:

OOP (= a class) can restrict the access of certain components inside an object

Comparing C with Java (relating to what you have learned)
 

Things you find in a C program:

Statements are (always) inside a function !!!

Comparing C with Java (relating to what you have learned)
 

C is not an Object Oriented Programming (OOP) Languages:

All global variables and all functions can be used by statements in any function !

Comment: later addition to the C programming language
 

  • Later, C has added:

      • static global variables    

    that are only accessible by functions defined inside the same source program file

    (C took some protection ideas from OOP....)

The start of a C program
 

  • A C program will start execution in the main( ) function

Your first C program: hello.c

The Hello World program in C:

   #include <stdio.h>

   int main( int argc, char* argv[] )            
   {
      printf( "Hello World !\n" );
   } 

 

 

 

Your first C program: hello.c
 

  • How to compile the hello.c program:

       gcc  hello.c    // generates executable file "a.out"  
      
       gcc -o hello hello.c // generate exec file "hello"
      

  • How to run the compiled (executable) code:

          a.out  // if compiled with gcc hello.c
       or
          hello  // if compiled with gcc -o hello hello.c  
      

Your first C program: hello.c

The Hello World program in C:

   #include <stdio.h>

   int main( int argc, char* argv[] )            
   {
      printf( "Hello World !\n" );
   } 

 

The #include <stdio.h> command tells the C pre-processor to include the file stdio.h inside /usr/include folder

The file /usr/include/stdio.h is C's standard IO header file

This file contains constant and variable definitions to allow C programs to perform commonly used input/output operations.

Your first C program: hello.c

The Hello World program in C:

   #include <stdio.h>

   int main( int argc, char* argv[] )            
   {
      printf( "Hello World !\n" );
   } 

 

This line is the header of the definition of the main() function

 

Your first C program: hello.c

The Hello World program in C:

   #include <stdio.h>

   int main( int argc, char* argv[] )            
   {
      printf( "Hello World !\n" );
   } 

The printf( ) function prints the parameter string to the terminal (output)

 

 

Definitions used for input/output by C programs
 

  • Objects needed for terminal input/output operations are defined/provided in the "header file" stdio.h

  • When a C program wants to perform I/O operations, it must include this "header file" with this line at the start (= head) of the C program:

         #include <stdio.h>             
      

  • stdin = the name (= identifier) of the standard input device (= the keyboard device)

  • stdout = the name (= identifier) of the standard output device (= the terminal)