From the course: C Essential Training

Basic syntax

- This chapter is about the basic syntax of the C language. The idea is to have you dive into the language with some real code right away. By necessity, this means that we'll use language features that have not yet been explained. It'll all be explained at some point in this course either in this chapter, or in later chapters. Don't let this get in your way. Go ahead, dive in, follow the exercises. If something isn't immediately obvious to you, that's okay. Just keep going, we'll get to it later. The basic syntax of C is very simple. A statement is a unit of code terminated by a semicolon. Statements are used for a variety of purposes to call functions, declare and initialize variables, or to operate on expressions. A function is a larger unit of code that may contain many statements. A function is designed to be reused or to be called by another statement. The main function is the main entry point of any C or C program. You never call main yourself. Main is called by the operating system when your program first launches. A variable holds a value or values for later use. In C variables must be declared before they're used. The variable may then be used to provide its value to statements and expressions later in your code. Most C files will have one or more include directives near the top of the file. The include directive is how you import libraries for use in your code. The library is a separate C file often with a .H file name extension. System libraries typically have no file name extension at all. The include directive includes the entire file during the compilation process. In this case, we include the iostream library which provides the C out object. In the rest of this chapter, we'll go through the basic syntax of C in a bit more detail. You'll learn how to construct a syntactically correct program, how to define variables, and how to use pointers and references. Take your time, experiment with the exercise files. Be sure to go through the whole chapter. Understanding these fundamental concepts will help you get the most out of the rest of the course.

Contents