C pointer initialization and dereferencing, what's wrong here?
Date : March 29 2020, 07:55 AM
I wish this help you You set the pointer to memory address 5, so that it points to whatever at address 5 might be. You probably wanted to make it point to an address where the value 5 is stored. For example: int v = 5; // Store the value 5 in a normal variable
int *n = &v; // Make n contain the address of v, so that it points to the
// contents of v
|
warning: assignment makes integer from pointer without a cast. whats wrong?
Date : March 29 2020, 07:55 AM
I hope this helps . strncpy returns a pointer which you are assigning to a char. (Actually, you are assigning it to an illegal address as r->label[NAMESIZE+1] is beyond the bounds of the array.) It should be struct rectangle *create_rectangle(struct point ul, struct point lr,
char *label) {
struct rectangle *r = malloc(sizeof(struct rectangle));
r->upperleft=ul;
r->lowerright=lr;
strncpy(r->label,label,NAMESIZE);
r->label[NAMESIZE] = '\0';
return r;
}
|
Whats wrong with the Null pointer
Date : March 29 2020, 07:55 AM
wish of those help You're passing the pointer by value, so inside the function you're actually assigning to a new pointer, not the original one. Change the function prototype to void StrIn(char *&sp).
|
Whats wrong with this one? C++ Array Pointer
Date : March 29 2020, 07:55 AM
Does that help Looking at what you are asked to do I think you just have to determine the highest and lowest int in the array and point to. You sort the array thats slower. I think it should look like that: #include<iostream>
using namespace std;
int main()
{
int kre_arr[10];
int *low;
int *high;
cout<<"Enter 10 Integers: ";
for (int i=0; i < 10; i++)
{
cin>>kre_arr[i];
}
//determine the lowest
low=&kre_arr[0];
for(int i=1;i<10;i++)
{
if(kre_arr[i] < *low)
{
low=&kre_arr[i];
}
}
//determine the highest
high=&kre_arr[0];
for(int i=1;i<10;i++)
{
if(kre_arr[i] > *high)
{
high=&kre_arr[i];
}
}
cout<<"lowest: "<<*low<<"\nhighest: "<<*high;
}
|
Initialization from incompatible pointer type [enabled by default] - whats wrong?
Date : March 29 2020, 07:55 AM
|