C Programming Tutorial

Best C Programming Tutorial for beginners covering basic to advanced ANSI C language topics on data types, Operators, Constants and Variables, Input/Output statements, Control structures, functions, loops, arrays, pointers, Format specifiers, memory management, Pre-processors, literals etc with simple and easy examples and detailed explanations.

C Overview and Basic Syntax

To learn any new programming language, for example C, C++, Java, etc., most commonly used approach is to write a basic HelloWorld program first and then learn the concepts from that. Let's follow the same approach here and first write a C program and learn about basic syntax of C programming.

Data Types in C Language

In a C program, data types are used to specify the type of data held by a variable or type of data returned/accepted by a function. If you remember the HelloWord Program we wrote earlier, you might have noticed that the main function returns an 'int' type response, which represents numbers.

C Qualifiers - Constant and Volatile type Qualifier

As mentioned earlier in the chapter of data types, C has some basic data types like 'int', 'float', 'char' etc. Each of which can hold a data of a specific type and has a set of specific properties defined for them. But what if you need to modify the properties of them? For example, if you want to make an 'int' variable constant, that means it's value shouldn't be changed from any where else in the program except the variable definition part. C type qualifiers can be used for such purposes.

C Type Casting with examples - float to int / int to char / int to long

The value of a variable or expression can be converted to another data type if desired. It is called type casting or type conversion. If you have a variable of data type long and you want to assign it to an int type variable, type casting can be used for that purpose. To type cast a variable or expression it must be preceded by the desired datatype as follows.

C Constants and Literals

Constants in C programming language, as the name suggests are the data that doesn't change. Constants are also known as literals. There are five types of constants or literals available in C programming language as shown below.

C Operators - Bitwise Operators and Conditional Operators

As the name suggests, bitwise operator operate at bit level. There are six bitwise operators and they are all binary operators, except '~'. These operators can be applied on operands of type int and char. Bitwise operators do not work on float or double. Different bitwise operators are explained in the table given below.

C Operator Precedence and Associativity Table with Examples

In the last two tutorials about operators in C language, we learned different types of operators, arity of operators and examples on how to use them. In this chapter we're going to learn about other important concepts about operators called operator precedence and operator associativity.

C Input and Output Statements

In the previous chapters of this C tutorial, you've learned the basic building blocks and concepts in C programming language. In this chapter, let's learn about how to perform input/output operations in C program. Input/output statements defines how we can read input from different input devices or write into different output devices. By input operation, we mean user providing values for the program through an external device (like keyboard) and by output operation, we mean writing results of computation to an external device, like monitor, printer etc. An input/output statement is nothing but standard function provided by C and each of them have a list of arguments enclosed in parentheses.

C Decision Making Control Structures - 'if', 'if - else', nested 'if', 'switch'

As discussed earlier in previous chapters of this C programming tutorial, different relational and logical operator checks if the relation between the operands is correct or not and return true and false value based on the result of comparison. What if you want to do some operations based on the result of these comparisons? Or what if you want to repeat some operations until a condition is met? C has different control structures available to help this situation.

Loops in C - for, while and do...while Loops

In previous chapter of this C programming tutorial we've learned about decision making control statements. But what if we want to run a piece of code multiple times? Writing same code block multiple times is bothersome as well as a waste of time and energy of the programmer. But fear not, C has another control structure in its sleeve called looping.

C 'break', 'continue' and 'goto' Statements to Control Program Flow

In the previous chapter about loops, we've learned how to make a code block run more than once using different loop structures. But what if you want to stop the loop at specific conditions or you want to skip the body of loop for a specific condition? 'break' and 'continue' statements helps you to achieve them. 'break' statement is also used with 'switch' statements. In this chapter let's look into 'break' and 'continue'statements in detail.

C Preprocessor Directives and Macros

C pre-processor directives help us to modify the program text before it is compiled. Basically, C pre-processors directives have the capability of simple text substitution tool, so that you can modify parts of program before it's actually compiled. We've already used few of the C pre-processors in the examples discussed in different chapters of this C programming tutorial. One of them is #include pre-processor directive which includes a header file into the program. Apart from including header files, there are other C pre-processor directives also which allow us to define a constant, write macros etc. C pre-processor comes in handy if you want some part of your code to be compiled depending on some condition. It is also known as conditional compilation.

C Functions Tutorial with Examples

C programs often need a piece of code to be executed more than once. We can use loops for such purposes, but what if we want to run them from different parts of the code? It can be simple validity check or a more complex operation, but as it is used from different parts of the program we can’t use loops. Of course, writing same code multiple times is a solution, but not very programmer like way (for example, if you want to change the algorithm, you've to change it at multiple places). It would be better if we can write the repeating code once and refer to it from where ever required. That’s exactly what functions in C language are for. In this chapter of C programming tutorial, let's look at the concept of "functions".

C Arrays - Dynamic, 2d and Multidimensional with Examples

In C programming practices, one of the frequently arising problems is to handle similar types of data and C language gives you a nice and swift way to deal this problem using arrays like other popular high level languages.

C Strings - Internal Working and Functions with example

Unlike other languages like C++, Java, etc. C does not provide any dedicated data type, rather it uses a character array to store strings. Since, in programming practices, we encounter frequently to handle strings. It is good to know how to do this in C.

C Pointers basics explained with examples

One of the interesting features that most C programmers enjoy and hates is pointers. Some C programmers enjoy it because it gives immense control over operations in programming. Reason for hating it is due to the fact that it can cause massive errors in program. If you can learn to handle this wisely, you will be a really good C programmer.

Structures in C Programming with Example

You have learned to store similar kind of data in C language using array. But in real life programming, sometimes you need a method to store dissimilar data. In that case, C provides you structures to deal with this.

C Storage Class Specifiers - auto, register, static and extern

We know that, a specific number of bytes of space is required to store a value of a variable as needed by the type of variable. For example, 'char' requires 1 byte, 'int' requires 2/4 byte and so on. This space can be allocated from the memory of the system or from processor registers. Register access is always faster than memory access. What if we can specify to the compiler about where to store the variable? Also, how long to keep the value of variable in memory, it's initial value etc? Storage class specifiers are used for that purpose. Using storage class specifiers we can specify

Planning to do an MBA?
A quick all-in-one MBA entry manual for MBA Aspirants. Book covers
  • Possible MBA Tests & Exam Preparation
  • Tips to choose right MBA Program
  • Essay, Resume & Letter of Recommendation
  • MBA Interview Preparation
  • MBA Financial Planning
Price - 6.99$
 

Popular Videos

How to speak to people

How to speak so that people want to listen.

Got a tip or Question?
Let us know