How to program "Hello, World!" in C Language (copy)

This course teaches you how to write "Hello, World!" in C programming language.

Getting Started (copy)

General Requirements

Text Editors

A few recommendations of mine are Notepad++, Sublime, Atom, or Visual Studio. Each of these are sufficient to complete the objectives of this course. You must have access to a working computer.

Assumptions

You should have a basic understanding of text editors (or IDE's) and compilation of executable programs. This purpose of this course is not to show you how to use a text editor or execute C language programs, but how to write proper executable C language.

Will this course show you how to use a text editor?

  • Yes
  • No

Will you be executing the code you learn how to write?

  • Yes
  • No

Choosing the Right Library (copy)

About C Libraries

C Libraries

The C programming language is widely popular among systems and hardware engineering. Compared to Javascript, Python, and many other modern programming languages, it is a low-level language. This means it is closer to the machine language of a computer or even the assembly language. Because C is a low level language it offers several libraries that may not be necessary. For the purpose of printing "Hello, World!" to the screen, we use the most basic and necessary library of C. 

#include <stdio.h>

The pound sign means "directive," so we are including a directive called "<stdio.h>." Any library, stated in the angular brackets is a C source directive, and with any directive comes C packages and options that allow programming to go above and beyond simple input and output. "<stdio.h>" contains the standard "scanf" and "printf" functions as well as other standard input and output functions. We will learn about "scanf" and "printf" later.

Final Thoughts

Without going to far in depth with what the functions do and how to use them in C, you only need to use "#include <stdio.h>" in order to print "Hello, World!" in C. And this is because that library contains everything you need to get those magic words on the screen.

Creating the Main Function (copy)

What is the Purpose of the Main Function?

Functions, Generally

A function in programming is a method to complete a task within code. Whether that task is to perform algebra or sort names in a file, the purpose of a function can vary widely.

The main() Function

The main() function is a requirement of every C code. Other than that, it's not a special function. In fact, as you progress in your C programming, you will use several functions along with your main() function.

What are those Parentheses for, after the "main"?

For the purpose of this course, we won't be writing anything other than "( )" following the "main." However, as you learn C, more advanced methods of functions use arguments within those parentheses, and these arguments are used within that function. Particularly, for the main() function, we have the option to pass in command line arguments in the form of (int argc, char** argv).

Using the main() function

While advancing with the C language, you'll notice many different methods of how programmers differently use the main() function. It is good practice to not place all of your code within the main() function as this can become unclear as to the purpose of the program. But, as for the purpose of this course, simply writing "Hello, World!" fits cleanly in the main() function.

Writing the Outline

The Type of the Main() Function

Each function written in C must have a return type. The main function's return type will return a value to the command line. We will create our main function to be of type 'int,' and the return type will be set to '0.'

The Scope of a Function

The scope of a function defines the bounds for which the variables and methods defined in it, are valid. The scope of a function begins with '{' and ends with '}'. Every function must have a scope or the program will not compile correctly.

The Main Function Outline

int main( ){


return 0;

}

Formatting the Correct Output (copy)

Untitled content