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:
- Stdio.h header.
- main() function and return statement.
- printf c function.
- 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 thatprintf("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.
- place your file on the desktop
- compile command: gcc lec1.c -o lec1.out then Press Enter
- this command will check your file if it contains any syntax errors
- if you have any errors it will appear after this command otherwise you file will be ready for running
- Run command : ./lec1.out then press Enter
- your screen should print hello world :)
check our next Session :)
No comments:
Post a Comment