Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C Language Cheatsheet

functions namely scanf() and print() respectively.The printf() function is used to print the output on the standard output device which is generally the display screen.Syntax of printf()where,The scanf() function is used to take input from the standard input device such as the keyboard.Syntax of scanf()where,InputOutputFormat specifiers are used to describe the format of input and output in formatted string. It is different for different data types. It always starts with %The following is the list of some commonly used format specifiers in C:Format SpecifierDescription%c%d%f%lf%p%s%u%%Escape sequences are the characters that are used to represent those characters that cannot by represented normally. They start with ( \ ) backslash and can be used inside string literals.The below table list some commonly used escape sequences:Operators are the symbols that are used to perform some kind of operation. Operators can be classified based on the type of operation they perform.There are the following types of operators in C:1.2.3.4.5.6.7.Conditional statements are used to execute some block of code based on whether the given condition is true. There are the following conditional statements in C:if statement contains a block of code that will be executed if and only if the given condition is true.Syntax of ifThe if-else statement contains the else block in addition to the if block which will be executed if the given condition is false.Syntax if-elseThe if-else-if ladder is used when we have to test multiple conditions and for each of these conditions, we have a separate block of code.Syntax of if-else-ifThe switch case statement is an alternative to the if-else-if ladder that can execute different blocks of statements based on the value of the single variable named switch variable.Syntax of switchThe conditional operator is a kind of single-line if-else statement that tests the condition and executes the true and false statements.Syntax of Conditional OperatorLoops are the control statements that are used to repeat some block of code till the specified condition is false. There are 3 loops in C:The for loop is an entry-controlled loop that consists initialization, condition, and updating as a part of itself.Syntax of forThe while loop is also an entry-controlled loop but only the condition is the part of is syntax.Syntax of whileThe do-while loop is an exit-controlled loop in which the condition is checked after the body of the loop.Syntax of do-whileJump statements are used to override the normal control flow of the program. There are 3 jump statements in C:It is used to terminate the loop and bring the program control to the statements after the loop.Syntax of breakIt is also used in the switch statement.The continue statement skips the current iteration and moves to the next iteration when encountered in the loop.Syntax of continueThe goto statement is used to move the program control to the predefined label.Syntax of gotoAn array is a fixed-size homogeneous collection of items stored at a contiguous memory location. It can contain elements from type int, char, float, structure, etc. to even other arrays.Strings are the sequence of characters terminated by a ‘\0’ NULL character. It is stored as the array of characters in C.C language provides some useful functions for string manipulation in header file. Some of them are as follows:S. No.FunctionDescription1.2.3.4.5.6.Pointers are the variables that store the address of another variable. They can point to any data type in CNote: The addressof (&) operator is used to get the address of a variable.We can dereference (access the value pointed by the pointer) using the same * operator.There are different types of pointers based on different classification parameters. Some of them are:Functions are the block of statements enclosed within { } braces that perform some specific task. They provide code reusability and modularity to the program.Function Syntax is divided into three parts:It tells the compiler about the existence of the function.where,It contains the actual statements to be executed when the function is called.Calls the function by providing arguments. A function call must always be after either function definition or function prototype.A function can be of 4 types based on return value and parameters:There is another classification of function in which there are 2 types of functions:Dynamic memory management allows the programmer to allocate the memory at the program’s runtime. The C language provides four functions for dynamic memory management which are malloc(), calloc(), realloc() and free().The malloc() function allocates the block of a specific size in the memory. It returns the void pointer to the memory block. If the allocation is failed, it returns the null pointer.SyntaxThe calloc() function allocates the number of blocks of the specified size in the memory. It returns the void pointer to the memory block. If the allocation is failed, it returns the null pointer.SyntaxThe realloc() function is used to change the size of the already allocated memory. It also returns the void pointer to the allocated memory.SyntaxThe free function is used to deallocate the already allocated memory.SyntaxA structure is a user-defined data type that can contain items of different types as its members. In C, struct keyword is used to declare structures and we can use ( . ) dot operator to access structure members.To use structure, we first have to define its template.orA union is also a user-defined data type that can contain elements of different types. However, unlike structure, a union stores its members in a shared memory location rather than having separate memory for each member.Union members can be accessed using dot operator ( . ) but only one member can store the data at a particular instance in time.Enumeration, also known as enum is a user-defined data type that is used to assign some name to the integral constant. By default, the enum members are assigned values starting from 0 but we can also assign values manually.File handling is the process of performing input and output on a file instead of the console. We can store, retrieve, and update data in a file. C supports text and binary files.We can perform some set of operations on a file and C language provide some functions for it.The preprocessor directives are used to provide instructions to the preprocessor that expands the code before compilation. They start with the # symbol.The following table lists all the preprocessor directives in C/C++:Description1.#define2.#undef3.#include4.#ifdef5.#endif6.#ifndef7.#if8.#else9.#pragmaC languages come bundled with some Standard Libraries that contain some useful functions to make it easier to perform some common operations. These are as follows:The header file contains functions to perform the arithmetic operations. The following table contains some common maths functions in C:Function NameFunction Description1.ceil(x)2.floor(x)3.fabs(x)4.sqrt(x)5.cbrt(x)6.pow(x , y)7.exp(x)8.fmod(x , y)9.log(x)10.log10(x)11.cos(x)12.sin(x)13.tan(x)



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

C Language Cheatsheet

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×