Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Beginners Cheatsheet for C Language, Cheat Sheet of C programming

The C Language Cheat Sheet is a reference manual for key grammar and ideas in the C programming language. It covers topics such as data types, variables, operators, control flow, arrays, functions, pointers, strings, input/output, structures, memory management, preprocessor directives, file handling, and common library functions. The cheat sheet presents each topic with clear syntax examples, making it simple to comprehend and use in practice. It is a helpful tool for both new and seasoned programmers who need to locate syntax examples and recollect crucial information when writing in C.

Typology: Cheat Sheet

2022/2023

Available from 07/16/2023

shivansh-rajbhar
shivansh-rajbhar 🇮🇳

1 document

Partial preview of the text

Download Beginners Cheatsheet for C Language and more Cheat Sheet C programming in PDF only on Docsity! Title : - C Language Cheat Sheet The C Language Cheat Sheet is an easy-to-use reference manual for key grammar and ideas in the C programming language. Beginning with a discussion of the fundamental syntax of a C programme, it gradually moves on to topics such as data types, variables, operators, control flow, arrays, functions, pointers, strings, input/output, structures, memory management, preprocessor directives, file handling, and common library functions. The cheat sheet presents each topic with clear syntax examples, making it simple to comprehend and use in practise. The cheat sheet focuses on the core concepts of C, such as declaring variables, carrying out operations with operators, directing the flow of programmes with conditional statements and loops, working with arrays and strings, utilising functions and recursion, manipulating memory with pointers, managing files, and utilising various other programming languages. You may rapidly refer to and review important C programming principles by utilising this cheat sheet. It is a helpful tool for both new and seasoned programmers who need to locate syntax examples and recollect crucial information when writing in C. This cheat sheet will provide you the crucial knowledge you need to create successful and efficient C programmes, whether you just need a fast refresher or a thorough understanding of the C language. **1. Basic Syntax:** ``` #include <stdio.h> int main() { // Code goes here return 0; } ``` **2. Data Types:** - int: Used for integers. ``` int age; ``` - float: Used for floating-point numbers. ``` float pi; ``` - char: Used for characters. ``` char grade; ``` - pointers: Used to store memory addresses. ``` int *ptr; ``` // code to execute if the condition is false } ``` - switch statements: ```c switch (expression) { case constant1: // code to execute if expression equals constant1 break; case constant2: // code to execute if expression equals constant2 break; default: // code to execute if expression doesn't match any constant } ``` - Loops: - for loop: ```c for (initialization; condition; increment/decrement) { // code to execute repeatedly } ``` - while loop: ```c while (condition) { // code to execute repeatedly as long as the condition is true } ``` - do-while loop: ```c do { // code to execute repeatedly } while (condition); ``` - break statement: ```c for (int i = 0; i < 10; i++) { if (i == 5) { break; // Exit the loop when i is 5 } } ``` - continue statement: ```c for (int i = 0; i < 10; i++) { if (i == 5) { continue; // Skip the iteration when i is 5 } } ``` **6. Arrays:** - Declare an array with a data type followed by the array name and size. ```c int numbers[5]; ``` - Initialize array elements individually or using an initializer list. ```c int numbers[5] = {1, 2, 3, 4, 5}; ``` - Access array elements using their index (starting from 0). ```c - Declare a pointer with a data type followed by an asterisk (*) and the pointer name. ```c int *ptr; ``` - Assign a memory address to a pointer using the & operator. ```c int number = 10; int *ptr = &number; ``` - Access the value at a memory address using the dereference operator (*) or arrow operator (->). ```c int value = *ptr; ``` - Perform pointer arithmetic using + and - operators. ```c int numbers[5] = {1, 2, 3, 4, 5}; int *ptr = numbers; int thirdNumber = *(ptr + 2); ``` **9. Strings:** - Declare a string as an array of characters. ```c char name[10]; ``` - Initialize a string with double quotes. ```c char greeting[] = "Hello"; ``` - Access individual characters using their index. ```c char firstChar = name[0]; ``` - Manipulate strings using library functions like strlen(), strcpy(), strcat(), strcmp(), etc. ```c char destination[20]; char source[] = "World"; strcpy(destination, source); ``` **10. Input/Output:** - Read input from the user using scanf() or fgets(). ```c int age; printf("Enter your age: "); scanf("%d", &age); ``` - Display output to the user using printf(). ```c int number = 10; printf("The number is: %d\n", number); ``` **11. Structures:** - Define a structure using the struct keyword, followed by the structure name and members. ```c struct Person { char name[20]; int age; }; ``` - Access structure members using the dot operator (.) or arrow operator (->). ```c
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved