Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I need store in a uint8_t pointer determinate positions of array.
Example:
uint8_t array[40] = {1,2,3,etc...}
uint8_t *pointer = array[5] - [25] . Save in pointer only positions between 5 to 25. I need in C++ language.
Thanks Community!
// Indices for the desired range of values.
constexpr std::size_t first = 5;
constexpr std::size_t last = 15;
// Create a new array with the appropriate size.
uint8_t array2[last - first];
// Copy the data to the array.
std::copy(array + first, array + last, std::begin(array2));
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How is this statement
int* p = new int[10];
p[10] = 5;
delete[] p;
different with this statement ?
int* p = new int[10];
*p = 5;
delete[] p;
I wanna what is wrong with the first code. I'm kinda new to C++, so any explanation is appreciated. Thanks.
The behaviour of p[10] is undefined as the array has only 10 elements and the first element is at position 0. You can access p[0] (which is the same as *p) to p[9] inclusive.
In other words, arrays in C++ are zero-based. Cf. Fortran, for example, where they are one-based.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
struct prac
{
int name[3];
char name1[12];
} b1, b2, c2;
main()
{
int i;
struct prac b2={1,2,3};
strcpy(c2.name1,"goodmorning");
printf("%s",c2.name1);
}
here to store the values in b2 array we just need to write b2={1,2,3} but if I want to store some values in the string c2 we need to call strcpy(), why it shows error if I write c2="goodmorning", rather than using strcpy()?
Because you can't assign to an array, only initialize it (which you do when you define the second b2 variable) or by copying to it (which you do with the strcpy call).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I came across these two terms
Int (*q)[3][4] and. int q[ ][3][4].
What's the difference these two terms?
And one more question .
Char a[ ]="abcd";
Char *p="abv";
a="ghj";
p="ajk";
Printf("℅s℅s",a,p);
Why this would not compile?
It won't compile because of the line:
a = "ghi"
This assigns a const char* to a char* directly. You can use strcpy to copy the string intead:
strcpy(a, "ghi")
You will still have warnings at this point, because you have not declared p as a const. You can fix this like so:
const char* p = "abv"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
VOID change(CHAR *TP, CHAR *FR, BOOL Vw)
{
CHAR *User, *NU, *CU = NULL, *Ref = NULL;
int Loop = 0;
<Some lines of code>
if(Loop == 0)
memcpy(Ref, FR, strlen(FR)+1);
CU = NU;
Loop++;
}
if(CU)
free(CU);
}// end of function
Ok so as you can see... the FR is a pointer to a character array.. and each time it sends the memory location..
and I have to copy it to Ref..
But all these are pointer variables..
What I need to do is.. I need to make a character array Lets say
AZ and it will contain,
AZ = the character array FR points to + "/abcd" +
then i will do a memcpy of AZ to Ref...
My problem is the FR variable is a pointer and I cant understand how to put that into a character array and then add characters to the final array..
Make sure that Ref has enough memory allocated to hold the strings that you want to concatenate.
Then you can use the strcpy() function to copy the first string to Ref, and strcat() to concatenate additional strings. For example:
strcpy(Ref, AZ);
strcat(Ref, "/abcd");
strcat(Ref, more_stuff);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is not logic :
int *ptr = &otherInt;
When we do that, ptr gives adress of otherInt, *ptr gives otherInt.
But we write explicitly that (*ptr) equals adress *ptr = &otherInt !
Logically, *ptr should give the adress, and ptr the otherInt.
Don't you think ?
I think you got it all wrong. Consider this:
int *ptr;
int otherInt = 10;
ptr = &otherInt; // Notice this line.
The asterisk is a part of the declaration, not the assignment.