Making your first program in C

Making your first program in C

#include <stdio.h>

int main() {

printf(“Hello World!”);

}

Ok, now rewrite the above in Dev-C++. To save, go to fileand choose save_as > choose a location > type the filename > add a .c suffix to the filename (if your filename was hello, it’s now hello.c) > click save

To run you program, click execute and choose compile and run.

If Dev-C++ fail, to run your program; it means you used the copy and paste tactic. So, go to your codes to delete and rewrite the double quotes.

Understanding these code

#include <stdio.h>

As the name says it, Dev-C++ was designed for C++. However, it can also work for C because C++ was developed in C. So, the above line tell Dev-C++ that we are creating a C program. If it was C++ we would use #include <iostream>. Stdio.h is short for Standard Input Output Header. We will learn more about headers next time.

int main() creates a function called main and two curry brackets { } are which hold the instructions for this function. The two parenthesis () are which indicate it is a function. Once you try to run a program made in C, it call a function call main. A C program can’trun with no main function.

printf is a built-in C function for displaying text on the screen. Contents between the two parenthesis () are passed to the function so that instructions in that function can access these contents. The double quotes are used to hold strings in C. String is another name for text.

 

 

© Mihigo ER Anaja

Write to me for more;

https://www.facebook.com/mihigoanaja

https://iblink.ning.com/members/mihigoeranaja

Post a Comment

0 Comments