How do you declare a pointer to an integer?

This question was previously asked in
RRB JE ECE 22 Apr 2025 Shift 1 CBT 2 Official Paper
View all RRB JE Papers >
  1. int *ptr;
  2. pointer int ptr;
  3. int ptr*;
  4. int ptr;

Answer (Detailed Solution Below)

Option 1 : int *ptr;
Free
General Science for All Railway Exams Mock Test
2.1 Lakh Users
20 Questions 20 Marks 15 Mins

Detailed Solution

Download Solution PDF

Explanation:

Declaring a Pointer to an Integer

Correct Option: 1) int *ptr;

Definition: In the C programming language, a pointer is a variable that stores the memory address of another variable. When you declare a pointer to an integer, you are creating a variable that can hold the address of an integer variable.

Syntax: The correct syntax to declare a pointer to an integer is int *ptr;. This statement declares a variable ptr as a pointer to an integer type. The asterisk (*) indicates that the variable is a pointer, and the type int specifies that the pointer will point to an integer.

Here is a breakdown of the correct option:

  • int - This specifies the data type of the variable that the pointer will point to. In this case, it is an integer.
  • * - The asterisk indicates that the variable being declared is a pointer.
  • ptr - This is the name of the pointer variable.

Example: Below is a simple example demonstrating the declaration and usage of a pointer to an integer:

int main() {
    int number = 10; / Declare an integer variable
    int *ptr; / Declare a pointer to an integer

    ptr = &number; / Assign the address of the integer variable to the pointer

    printf("Value of number: %d\n", number); / Output the value of the integer variable
    printf("Address of number: %p\n", &number); / Output the address of the integer variable
    printf("Value stored in ptr: %p\n", ptr); / Output the address stored in the pointer
    printf("Value pointed to by ptr: %d\n", *ptr); / Output the value pointed to by the pointer

    return 0;
}

In this example, number is an integer variable, and ptr is a pointer to an integer. The address of number is assigned to ptr. The pointer ptr now holds the memory address of the integer variable number. The value pointed to by ptr can be accessed using the dereference operator (*).

Latest RRB JE Updates

Last updated on Jun 7, 2025

-> RRB JE CBT 2 answer key 2025 for June 4 exam has been released at the official website.

-> Check Your Marks via RRB JE CBT 2 Rank Calculator 2025

-> RRB JE CBT 2 admit card 2025 has been released. 

-> RRB JE CBT 2 city intimation slip 2025 for June 4 exam has been released at the official website.

-> RRB JE CBT 2 Cancelled Shift Exam 2025 will be conducted on June 4, 2025 in offline mode. 

-> RRB JE CBT 2 Exam Analysis 2025 is Out, Candidates analysis their exam according to Shift 1 and 2 Questions and Answers.

-> The RRB JE Notification 2024 was released for 7951 vacancies for various posts of Junior Engineer, Depot Material Superintendent, Chemical & Metallurgical Assistant, Chemical Supervisor (Research) and Metallurgical Supervisor (Research). 

-> The selection process includes CBT 1, CBT 2, and Document Verification & Medical Test.

-> The candidates who will be selected will get an approximate salary range between Rs. 13,500 to Rs. 38,425.

-> Attempt RRB JE Free Current Affairs Mock Test here

-> Enhance your preparation with the RRB JE Previous Year Papers

Get Free Access Now
Hot Links: teen patti master list teen patti all teen patti master apk download teen patti 3a teen patti 100 bonus