How to declare multiple pointers in one line with C++

2 Answers

0 votes
#include <iostream>

int main() {
   const char *str1 = "cpp", *str2 = "c";
   
   std::cout << str1 << "\n";
   std::cout << str2 << "\n";
}
 
 
 
 
/*
run:
 
cpp
c
 
*/

 



answered Feb 1, 2023 by avibootz
0 votes
#include <iostream>

int main() {
    int arr[] = {4, 8, 9, 5, 7};
    int *p1, *p2, *p3;
   
    p1 = &arr[0];
    std::cout << *p1 << "\n";
   
    p2 = &arr[1];
    std::cout << *p2 << "\n";
    
    p3 = &arr[3];
    std::cout << *p3 << "\n";
}
 
 
 
 
/*
run:
 
4
8
5
 
*/

 



answered Feb 1, 2023 by avibootz

Related questions

1 answer 129 views
2 answers 223 views
1 answer 261 views
1 answer 223 views
1 answer 138 views
1 answer 147 views
...