Which of the following operations cannot be performed on pointers in ...
There are operations like increment, decrement, etc that can be performed on printers but there are operation that can’t be performed on pointers are –addition of 2 addresses; Division of 2 addresses; Modulo operation on pointer; bitwise AND, OR, XOR operations on pointer; NOT operation on pointer.
View all questions of this test
Which of the following operations cannot be performed on pointers in ...
Explanation:
In C programming language, pointers are variables that store memory addresses of other variables. Pointers can be used to perform various operations like accessing memory locations, manipulating data, and performing arithmetic operations. However, there are certain operations that cannot be performed on pointers.
Addition of two pointers:
Adding two pointers together is not allowed in C. This operation is not meaningful because adding two memory addresses does not provide any useful result. It doesn't make sense to add the addresses of two variables or memory locations.
Subtraction of a number from a pointer:
Subtracting a number from a pointer is a valid operation in C. When a number is subtracted from a pointer, the resulting pointer points to a memory location that is "number" units before the original pointer location. This is useful in scenarios where you want to access a specific element in an array based on its index.
Subtraction of one pointer from another:
Subtracting one pointer from another is a valid operation in C. This operation yields the number of elements between the two pointers. It is useful in scenarios where you want to determine the distance between two elements in an array or measure the size of a dynamically allocated memory block.
Addition of a number to a pointer:
Adding a number to a pointer is a valid operation in C. When a number is added to a pointer, the resulting pointer points to a memory location that is "number" units after the original pointer location. This is useful in scenarios where you want to access a specific element in an array based on its index.
Therefore, the correct answer is option 'A' - Addition of two pointers cannot be performed in C.
To make sure you are not studying endlessly, EduRev has designed Railways study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Railways.