This C Cheatsheet is For You!
  1. C
  2. Basic syntax and functions from the C programming language.

  3. Boilerplate Code
  4. #include <stdio.h>
    int main()
    {
    return(0);
    }
    
  5. printf function
  6. It is used to show output on the screen

    printf("Hello Kashmir!");
    
  7. scanf
  8. It is used to take input from the user

    scanf("placeholder", variables)
    
  9. Comments
  10. A comment is the code that is not executed by the compiler, and the programmer uses it to keep track of the code.

    // It's a single line comment
    /* It's a 
    multi-line
    comment
    */
    
  11. Data types
  12. The data type is the type of data

    Typically a single octet(one byte). It is an integer type
    char variable_name;
    int variable_name;
    A single-precision floating-point value
    float variable_name;
    A double-precision floating-point value
    double variable_name;
    
  13. Void type
  14. Represents the absence of the type

    Void
    
  15. Alarm or Beep,Backspace,Newline,Tab,Single quote
  16. \a
    \b
    \n
    \t
    \''
    
  17. Conditional Instructions
  18. Conditional statements are used to perform operations based on some condition.

    if (/* condition */)
    {
    /* code */
    }
    
  19. if-else statement
  20. if (/* condition */)
    {
    /* code */
    }
    else{
    /* Code */
    }
    
  21. if else-if Statement
  22. if (condition) {
    // Statements;
    }
    else if (condition){
    // Statements;
    }
    else{
    // Statements
    }
    
  23. Switch Case Statement
  24. It allows a variable to be tested for equality against a list of values (cases).

    switch (expression) 
    {
    case constant-expression: 
    statement1;
    statement2;
    break;
    case constant-expression: 
    statement;
    break;
    ...
    default: 
    statement;
    }
    
  25. Loops
  26. Iterative statements facilitate programmers to execute any block of code lines repeatedly and can be controlled as per conditions added by the programmer.

    while (/* condition */)
    {
    /* code */
    }
    
  27. do-while loop
  28. do
    {
    /* code */
    } while (/* condition */);
    
  29. For loop
  30. for (int i = 0; i < count; i++)
    {
    /* code */
    }
    
  31. Break Statement,Continue Statement
  32. break keyword inside the loop is used to terminate the loop

    continue keyword skips the rest of the current iteration of the loop and returns to the starting point of the loop

    break;
    continue; 
    
  33. Functions & Recursion
  34. Functions are used to divide an extensive program into smaller pieces. It can be called multiple times to provide reusability and modularity to the C program.

    return_type function_name(data_type parameter...){ 
        //code to be executed 
        }
    
  35. Recursion
  36. void recurse()
    {
    ... .. ...
    recurse();
    ... .. ...
    }
    
  37. Pointers
  38. Pointer is a variable that contains the address of another variable,

    Declaration
    datatype *var_name;
    
  39. Arrays
  40. An array is a collection of data items of the same type.

    data_type array_name[array_size];
    
  41. Strings,gets() function,puts("string");
  42. A string is a 1-D character array terminated by a null character ('\0')

    It allows you to enter multi-word string

    It is used to show string output

    char str_name[size];
    gets("string");
    puts("string");
    
  43. String Functions
  44. strlen(string_name);
    It is used to calculate the length of the string
    strcpy(destination, source);
    It is used to copy the content of second-string into the first string passed to it
    strcat(first_string, second_string);
    It is used to concatenate two strings
    strcmp(first_string, second_string);
    It is used to compare two strings
    
  45. Structures
  46. The structure is a collection of variables of different types under a single name. Defining structure means creating a new data type.

    struct structureName 
    {
    dataType member1;
    dataType member2;
    ...
    };