Learn Advanced Placement Tests Coaching from the Best Tutors
Search in
void main ( )
{
int a [4];
int *p;
P=a;
*P=10;
P++;
*P=20;
P=&a[2];
*P=30
for (int i=0; i<3; i++)
cout <<a[i] <<" , " ,
Write output
Hi Anya, your code is full of syntactical errors. Rectified cde is as follows:
#include <iostream>
using namespace std;
int main() {
int a[4]; // Array of size 4
int *p; // Pointer to integer
p = a; // Assign the address of the first element of array 'a' to pointer 'p'
*p = 10; // Set the value at the memory location pointed to by 'p' (i.e., a[0]) to 10
p++; // Move pointer to the next element in the array
*p = 20; // Set the value at the memory location pointed to by 'p' (i.e., a[1]) to 20
p = &a[2]; // Set pointer 'p' to point to the third element of the array 'a'
*p = 30; // Set the value at the memory location pointed to by 'p' (i.e., a[2]) to 30
// Loop to print the first three elements of the array
for (int i = 0; i < 3; i++) {
cout << a[i] << " , "; // Print the array values followed by commas
}
return 0;
}
Output:
10 , 20 , 30 ,
read lessRelated Questions
How do apprach to an unknown problem to construct its solution? Especially when do you face any programming challenge.
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Why Studying Abroad is becoming a popular...
Why Study Abroad? With every passing year, the number of students from India applying for overseas education is increasing. Here, let us explore why studying abroad has become such a popular option for students of all ages. Study Abroad Benefits A wide variety of programs and world class faculty: One of...
Thinking of Studying Abroad? Your Guide to...
Once you decide to go abroad to pursue your studies, an extensive preparation is necessary. Following a step-by-step process helps you achieve your goal without getting overwhelmed by the number of things that need to be done! I. Planning: - 1. What, where and when? First decide what kind of program you want to...
Bank P.O Exam Guide
Bank P.O is one of the most talked about examination for bank recruitment in India. P.O stands for Probationary Officer which is an entry level position in banks, which are especially for fresh graduates or a person without any prior experience. The probation period for Bank P.Os is generally 2 years in which they’re trained...
10 Tricks to Remember What You Studied
It is not true that every student is lethargic and loves to be the couch potato. Some students do put immense effort for their examinations. Where some book-worms study day in and out without a break, with an ultimate objective to crack the competitive examination or to score the highest mark. But, the saddest part is that,...
Looking for Advanced Placement Tests Coaching classes?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for Advanced Placement Tests Coaching Classes are on UrbanPro
The best Tutors for Advanced Placement Tests Coaching Classes are on UrbanPro