What does the parameter definition in front of the malloc function mean?

Updated on technology 2024-02-09
5 answers
  1. Anonymous users2024-02-05

    This is not a parameter definition, but a forced type conversion. Forcibly converts the memory of the new request to the desired type.

  2. Anonymous users2024-02-04

    For example: int* p = (int *)malloc(size);

    What type of pointer your pointer is, what type of malloc space you apply for will be returned

    Malloc returns void*, so it's best to force it to the type you need.

  3. Anonymous users2024-02-03

    unsigned char maxval() const throw()

    unsigned char maxval() const This is a constant function, throw() is an exception description! If the function throws an exception, the exception that is thrown will be one of the ones included in that description! Here, throw() does not specify the type of exception, the function can throw any type of exception!

    If you write unsigned char maxval() const throw(runtime error), if the function throws an exception, it will be an object of type runtime error! You can use try to catch exceptions, so you can find out when something went wrong there!

  4. Anonymous users2024-02-02

    First of all, the function prototype of malloc looks like this, extern void *malloc(unsigned int num bytes);

    The return value is void*, which is a pointer of type void, which means that it can be arbitrarily cast to a pointer of other types.

    The argument is an unsigned int value, which is passed the size of the static heap you want to apply, in bytes.

    The meaning of the function is to request a space the size of your parameters, and return a pointer to this space to you, and you can use this space with this pointer.

    thus (int)malloc(sizeof(int)); int)malloc(sizeof(int*))

    These two are misspellings, and although grammatically they can be used, few people will use them that way... Unless it's for some special purpose. This is because it is not necessary to cast a pointer to an int type and then use it as a number of int types.

    This is usually a cast pointer.

    and (int*)malloc(sizeof(int)); int*)malloc(sizeof(int*))

    The difference is in sizeof, is int the same size as int*?

    If it is a 32-bit compiler, since the sizeof(int) and sizeof(int*) values are both 4, both of which are 4 bytes in size, the result of calling the function is the same.

    For a 64-bit compiler, sizeof(int) is 8 and sizeof(int*) is 4, the result is different.

    Although the result of the 32-bit machine is the same, there is a difference in the meaning of the representation (writing ** a lot is for others to see), because the former means that the former means to apply for 4 bytes of space as int data, and the latter means to apply for 4 bytes of space as int* data to use, so although the result is the same, it is still necessary to pay attention to the meaning of the representation.

  5. Anonymous users2024-02-01

    ( int *)malloc( sizeof(int) ) This is the correct way to write it, and the rest is all wrong to write!

Related questions
8 answers2024-02-09

Analysis] Inverse matrix definition: If the nth-order matrix a and b satisfy ab=ba=e, then a is said to be reversible, and the inverse matrix of a is b. >>>More

4 answers2024-02-09

For the teacher to understand and memorize what he said in class, it is important to have an appropriate amount of [review] and [do questions] after class, and it is very important to write the logical order in the multi-thinking function, and then it is necessary to have appropriate exercises. Junior high school!? High school.

7 answers2024-02-09

1) Knowing that the quadratic function f(x) satisfies f(2x+1)=4x-6x+5, find f(x) t = 2x +1 ==> x = (t -1) 2 f(2x+1)=4x-6x+5 ==> f(t) = 4* [t-1) 2] 2 - 6 * t-1) 2 +5 ==> f(t) = (t-1) 2 - 3(t-1) +5 ==> f(t) = t 2 - 2t +1 - 3t + 3 +5 ==> f(t) = t 2 - 5t + 9 f(x) = x 2 - 5x + 9 (2) known function f(x+1 x) = x+1 x, find f(x) f(x +1 x) = x 2 + 1 x 2 = (x + 1 x) 2 - 2 t = x +1 x f(t) = t 2 - 2 f(x) = x 2 - 2

16 answers2024-02-09

Oh, it's actually very simple, the idea is the dirichlet function, that is. >>>More

12 answers2024-02-09

I'm not a math whiz, but I hope the following helps! ~

Let the function f(x) (x 1)ln(x 1), if for all x 0, f(x) ax holds, and find the range of the value of the real number a (2006 national .).Monday, 26 March 2007 at 13:41 >>>More