Which of the following is the correct way to declare a pointer variabl...
The correct way to declare a pointer variable in C is option 'A': int* ptr.
Explanation:
- In C, a pointer is a variable that stores the memory address of another variable.
- To declare a pointer variable, we use an asterisk (*) symbol after the data type.
- The asterisk (*) indicates that the variable is a pointer.
- The name of the pointer variable can be any valid variable name.
- In this case, the pointer variable is named 'ptr'.
- The data type of the pointer variable is 'int', which means it can store the memory address of an integer variable.
Let's break down the options and see why option 'A' is correct:
a) int* ptr;
- This is the correct way to declare a pointer variable in C.
- The data type is 'int' and the pointer symbol (*) is placed after the data type.
- The variable name is 'ptr'.
b) int ptr*;
- This is an incorrect way to declare a pointer variable in C.
- The pointer symbol (*) should be placed before the variable name, not after.
- So, 'int ptr*' is not a valid declaration.
c) int ptr;
- This is a valid declaration, but it declares a regular integer variable, not a pointer variable.
- Without the pointer symbol (*), 'int ptr' declares an integer variable named 'ptr'.
d) *int ptr;
- This is an incorrect way to declare a pointer variable in C.
- The pointer symbol (*) should be placed after the data type, not before.
- So, '*int ptr' is not a valid declaration.
In summary, the correct way to declare a pointer variable in C is 'int* ptr'. This declaration indicates that 'ptr' is a pointer variable that can store the memory address of an integer variable.
Which of the following is the correct way to declare a pointer variabl...
The correct way to declare a pointer variable in C++ is by using the asterisk (*) after the type name. For example, 'int* ptr'; declares a pointer variable named 'ptr' that can hold the address of an integer.
To make sure you are not studying endlessly, EduRev has designed EmSAT Achieve study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in EmSAT Achieve.