+ 1
Entering an array of 10 elements replacing the final element of the array with the 2nd element using the pointer
Help me I just started learning C++ please
12 Respuestas
0
Алиаскар Куватов ok,
#include <stdio.h>
int main()
{
int a[10] = {1,2,3,4,5,6,7,8,9,0};
int* p = a;
int t = *(p+9);
*(p+9) = *(p+1);
*(p+1) = t;
printf("%d\n%d", a[9], a[1]);
return 0;
}
// you can use any loop to get input, but idea that i used can be applied here
https://code.sololearn.com/c08l2TC7g7zb/?ref=app
+ 1
Ok Thank you
0
do you mean something like this?
#include <stdio.h>
int main()
{
int a[10] = {1,2,3,4,5,6,7,8,9,0};
int* p = a;
*(p+9) = *(p+1);
printf("%d", a[9]);
return 0;
}
// it’s a C file, didn’t notice the tag was C++. But should be the same.
https://code.sololearn.com/c08l2TC7g7zb/?ref=app
0
no
0
Enter the array data, and swap the second and last element of the array.
0
Input: 1 2 3 4 5 6 7 8 9 0
Output: 1 0 3 4 5 6 7 8 9 2
0
Input: 1 2 3 4 5 6 7 8 9 0
Output: 1 0 3 4 5 6 7 8 9 2
0
Алиаскар Куватов did you see my code shows the same thing. learn a bit more before complaining
0
Sorry
0
Can I send my code so that you can fix it
0
I can’t fix it for you. I showed almost everything. You can use a while/for to get input. Rest should be the same.
0
Алиаскар Куватов you’re welcome