1)Is it right?
main()
{
int *a,*b;
cin>>&a>>&b;
}
2)How can we get a random number between -7 & 10?
x=-7+rand()%18
3)Is it right???
struct phone{
int ph;
string s;
};
main()
{
phone arr[10];
for(int i=0;i<10;i++){
cin>>arr[i].ph>>arr[i].s;
}
4)Do we have "string *p" like " char *p"?
5)How can we put a stack as input of a function?(make a simple example please.)
1. No. In Java, pointers are hidden/implied. In C++ they're explicit.
1 2 3 4
int main() {
int a, b;
cin >> a >> b;
}
2. Does that include 10?
3. std::string is a string object defined in the standard library, so you say string s, so no.
4. In much the same way a std::string is an object in the standard library, there's also std::stack. You simply instantiate one and pass it by reference. (Sorry, no example right now.)
#include <iostream>
#include <random>
#include <chrono>
int main()
{
// obtain a seed from the system clock:
unsigned seed = static_cast<unsigned> (std::chrono::system_clock::now().time_since_epoch().count());
// create a generic random engine generator
std::default_random_engine rd(seed);
// discard some initial values for better randomization
rd.discard(1000);
// set a distribution range (-7 to 10 inclusive)
std::uniform_int_distribution<int> dist(-7, 10);
// generate a random number
int number = dist(rd);
std::cout << "The random number is: " << number << '\n';
}
you simply can try to test your code in arbitrary Compile such as g++ in Linux
and see if that code is correct or not.
i try and find this way is correct:
1 2 3
int *a,*b;
cin>> *a >> *b;
cout << *a;
try to other thing such as bellow cause error, Read Compiler Output Messages.
This is NOT correct. You declare 2 pointers and don't assign them. Then when you read into them, you overwrite unknown memory--whatever is pointed to by the garbage they previously contained.
The following would be fine:
1 2 3 4 5
int i, j;
int *a = &i;
int *b = &j;
cin>> *a >> *b;
cout << *a;
Now when you read in the values they get put into specific memory locations.
However, I @OP was looking for @kbw showed in post #2.