C Pointer Arithmetic
1. What is Pointer Arithmetic? Pointer arithmetic allows you to move a pointer through memory based on the size of the data type it points to. You can perform arithmetic operations like: Increment: ptr++...
1. What is Pointer Arithmetic? Pointer arithmetic allows you to move a pointer through memory based on the size of the data type it points to. You can perform arithmetic operations like: Increment: ptr++...
1. Array Name as a Pointer In C, the name of an array is treated as a pointer to its first element. That means:
|
1 2 |
int numbers[5] = {10, 20, 30, 40, 50}; int *ptr = numbers; // same as int *ptr = &numbers[0]; |
numbers → address of the first element (numbers[0])...
1. What is a Pointer? A pointer is a variable that stores the memory address of another variable. Instead of holding a value directly, it holds where the value is stored. Syntax:
|
1 |
data_type *pointer_name; |
...
1. What is a Memory Address? Every variable in C is stored at a specific location in memory. The memory address is the location where the variable’s value is stored. You can find the...
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:...