Cheat Sheets Flashcards
(45 cards)
#include<stdio.h>
and int main(){ return(0); } in C programming?
This is boilerplate code in C. #include<stdio.h> includes the standard input-output library, and int main(){ return(0); } is the basic structure of a C program where execution begins and returns 0 on successful completion.</stdio.h>
What is the purpose of the printf function?
It is used to show output on the screen.
Example: printf(“Hello World!”).
How is the scanf function used?
It is used to take input from the user with the syntax scanf(“placeholder”, variables).
What is a comment in C, and what are the two types?
A comment is code not executed by the compiler, used by programmers to track code. The two types are single-line comments (e.g., // It’s a single line comment) and multi-line comments (e.g., /* It’s a multi-line comment */).
What are the basic data types in C?
The basic data types are: char (typically a single byte, integer type), int (most natural size of integer for the machine), float (single-precision floating-point value), double (double-precision floating-point value), and void (represents the absence of type).
What are escape sequences, and give examples?
An escape sequence is a sequence of characters starting with a backslash that doesn’t represent itself inside a string literal. Examples include: \a (Alarm or Beep), \b (Backspace), \f (Form feed), \n (Newline Character), \r (Carriage return), \t (Tab), \ (Backslash), ' (Single quote), " (Double quote), \? (Question mark), \nnn (Octal No.), \xhh (Hexadecimal No.), and \0 (Null character to terminate a string).
What are conditional instructions used for in C?
Conditional statements are used to perform operations based on some condition.
Explain the if statement syntax.
The if statement has the syntax: if (condition) { /* code */ }.
How does an if-else statement work?
An if-else statement executes code based on a condition: if (condition) { /* code / } else { / Code */ }.
Describe the if else-if statement.
The if else-if statement allows for multiple conditions: if (condition) { // Statements; } else if (condition) { // Statements; } else { // Statements }.
What is a switch-case statement?
It allows a variable to be tested for equality against a list of values (cases).
What is the syntax for a switch-case statement?
The syntax is: switch (expression) { case constant-expression: statement1; statement2; break; case constant-expression: statement; break; … default: statement; }.
What is the purpose of iterative statements?
Iterative statements facilitate programmers to execute any block of code lines repeatedly and can be controlled as per conditions added by the programmer.
How does a while loop function?
It allows execution of statements inside the block of the loop until the condition of the loop succeeds.
What is a do-while loop, and how does it differ from a while loop?
A do-while loop is an exit-controlled loop. It is similar to the while loop, but its body is executed at least once even if the expression is false.
Explain the for loop in C.
A for loop is used to iterate statements or a part of the program several times. It is frequently used to traverse data structures like arrays and linked lists. The syntax is for (int i=0; i < count; i++) { /* code */ }.
What is the function of the break statement?
The break keyword inside a loop is used to terminate the loop.
What does the continue statement do?
The continue keyword skips the rest of the current iteration of the loop and returns to the starting point of the loop.
Why are functions used in C programming?
Functions are used to divide an extensive program into smaller pieces. They can be called multiple times to provide reusability and modularity to the C program.
What is the syntax for a function definition?
The syntax is return_type function_name(data_type parameter…) { //code to be executed }.
What is recursion in programming?
Recursion is when a function calls a copy of itself to work on a minor problem. A function that calls itself is known as a Recursive function.
What is a pointer in C, and how is it declared?
A pointer is a variable that contains the address of another variable. It is declared using the syntax datatype *var_name;.
What is an array in C, and how are its elements accessed?
An array is a collection of data items of the same type. It is declared as data_type array_name [array_size];, and an element is accessed as int variable_name = array[index];.
What is a string in C, and how is it declared?
A string is a 1-D character array terminated by a null character (‘\0’). It is declared as char str_name[size];.