C User Input
1. Basic Input Functions In C, user input is mainly taken using: scanf() → Reads formatted input getchar() → Reads a single character gets() → Reads a string (unsafe, avoid using) fgets() → Reads...
1. Basic Input Functions In C, user input is mainly taken using: scanf() → Reads formatted input getchar() → Reads a single character gets() → Reads a string (unsafe, avoid using) fgets() → Reads...
1. Include the Header #include <string.h> All standard string functions are defined in <string.h>. 2. Common C String Functions Function Description Example strlen(str) Returns the length of a string (excluding \0) int len =...
1. What are Special Characters in C? Special characters are prefixed with a backslash \. They are used for newline, tab, quotes, backslash, etc. Mainly used in strings and character constants. 2. Common Special...
1. What is a String in C? In C, a string is an array of characters terminated by a null character \0. The null character \0 marks the end of the string. Example of...
1. What is a Multidimensional Array? A multidimensional array is an array of arrays. The most common is a 2D array, which can be thought of as a table with rows and columns. Syntax...
1. Storing Marks of Students Suppose you have 5 students and want to store their marks. Instead of creating 5 separate variables, use an array:
|
1 2 3 4 5 6 7 8 9 10 11 |
#include <stdio.h> int main() { int marks[5] = {85, 90, 78, 92, 88}; for (int i = 0; i < 5; i++) { printf("Student %d: %d marks\n", i + 1, marks[i]); } return 0; } |
Output: Student 1: 85 marks Student 2:...
1. Looping Through an Array Using for Loop The most common way to process array elements is with a for loop. Example: Print all elements of an array #include <stdio.h> int main() { int...
1. Declaring Array Size When you declare an array, you must specify its size (number of elements): int numbers[5]; // array can hold 5 integers Array size must be a positive integer constant. Example:...
1. What is an Array? An array is a collection of elements of the same data type stored at contiguous memory locations. Arrays allow you to store multiple values using a single variable name....
1. What is break? The break statement immediately exits the loop (or switch statement). No further iterations are executed after break. Syntax: for (int i = 1; i <= 10; i++) { if (i...