In this lab, we will write our very first C program. It is customary in programming to name your first program hello world so we will do that here as well.
The general steps we will be following to get our first program running are:
First clear out and existing code inthe Jdoodle editor by selecting all the code and then press the delete key on your computer.
Once the editor has opened, paste in the following code:
#include <stdio.h> int main() { // printf() displays the string inside quotation printf("Hello, World!\n"); return 0; }
When the code is in the editor, execute the program by clicking the Execute button underneath the code editor in the Jdoodle Window.
You should see the following output:
Hello,World!
Now that we have our program running, we can make a small change and rerun the program. Make a simple change to the printf statement by adding your name. You can see the following code as an example.
#include <stdio.h> int main() { // printf() displays the string inside quotation printf("Hello, World, my name is Eric!\n"); return 0; }
When the code is in the editor,we will compile and rerun the program just like we did in the earlier step by clicking the Execute button in the Jdoodle window.
You should see the following output:
Hello, World, my name is Eric!
You will notice that the last line of the program returns 0. This
is a standard convention that C program follo that a 0 value indicates that the program exited without any issues. Can the return value to -1 and rerun the program. Your code syoud look like this:
#include <stdio.h> int main() { // printf() displays the string inside quotation printf("Hello, World, my name is Eric!\n"); return -1; }
You should see the following output:
Hello, World, my name is Eric! Command exited with non-zero status 255
reset the return valus of you program back to 0 and rerun to make sure everything is ok.
Congratulations you have written your first C program! Although this is a simple example, you will now see the flow of developing C programs which is:
This lab runs on containers, so as soon as you quit your changes will be lost. You can save your C program by copying and pasting from the Jdoodle editor if you would like to save this program to your computer.
File: labc_hello.md
© Copyright 2023 Destin Learning