Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The usage of false, error, overflow, and infeasible in the C language data structure is similar. Where are they used?
The usage of false, error, overflow, and infeasible in the C language data structure is similar. Where are they used?

Overflow is generally used in the parameters of exit. For example, when creating a pointer, it is generally judged whether the memory is allocated successfully. If it is not successful, returnexit(overflow) is usually called;

infeasible means infeasible. Yes, generally in a certain judgment, if something is not feasible, returninfeasible will be returned. For example: when searching for the successor element, if it is the last element, then searching for its successor is not feasible, and then returninfeasible will be returned;

The return type of many functions is Status. Here Status is the intl type defined with typedef, that is: typedefintStatus; in such a function, true or falseok or error is returned according to different situations.

StatusListEmpty(SqListL)

{

//If L is an empty table, return TRUE, otherwise return FALSE

if( L.length==0)

{

returnTRUE;

}

else

{

returnFALSE;

}

}

StatusGetElem(SqListL,inti,ElemType*e)

{

//Use e to return the value of the i-th element in L, 1=

if(i<1||i>L.length)

{

returnERROR;

}

*e=*(L.elem+i-1);

returnOK;

}

Extended information

The C language append() method adds elements to the slice

Go language content The built-in function append() can dynamically add elements to the slice. Each slice points to an underlying array that can hold a certain number of elements.

When the underlying array cannot accommodate the new elements, the slice will automatically "expand" according to a certain strategy, and the underlying array pointed to by the slice will be replaced. The "expansion" operation often occurs when the append() function is called.

For example:

Baidu Encyclopedia—C language