Monday, November 19, 2012

Programming Session 1



Operating System : Linux Ubuntu 
Compiler : G++ and GCC

now make new document and name it lec1.c and press enter, to be sure that g++ and gcc compilers your file  image will be changed to big C letter.

in this session we are going to learn the following topics:
  1. Stdio.h header. 
  2. main() function and return statement.
  3. printf c function.  
  4. how to compile and run 

stdio.h header

a recommended header used for using printing and scanning and other basic commands in c programming functions.

main() function 

the start point of a program is the main function so your code would be written in this function. 

return 

the end point of a program.

so your document should look like this
#include<stdio.h>
int main()
{
        //your code 
return 0;
any program should include the previous commands.

the previous program doesn't do anything yet as we didn't write any code between the start and the end point.


Printf Function 

this function used when we need to print something on the screen , if we need to write "hello world" on the screen we write it like that
printf("hello world"); 
so your code should look like this 

#include<stdio.h>
int main()
{
       printf("hello world"); 
return 0;

how to compile and run your program? 

press alt+ctrl+t  to open your terminal so we could compile and run our program.

  1. place your file on the desktop 
  2. compile command:  gcc lec1.c -o lec1.out then Press Enter 
    1. this command will check your file if it contains any syntax errors
    2. if you have any errors it will appear after this command otherwise you file will be ready for running
  3. Run command : ./lec1.out then press Enter
  4. your screen should print hello world :) 
congratulations you have finished your first program :)
check our next Session :)

No comments:

Post a Comment