Creating an Array: Difference between revisions

Content added Content deleted
(→‎[[C]]: Removed syntax highlighting)
Line 52: Line 52:
'''Libraries:''' Standard
'''Libraries:''' Standard
Dynamic
Dynamic
#include <stdlib.h> /* for malloc */
<highlightSyntax language=C>
#include <stdlib.h> /* for malloc */
#include <string.h> /* for memset */
int n = 10 * sizeof(int);
#include <string.h> /* for memset */
int n = 10 * sizeof(int);
int *myArray = (int*)malloc(n);
int *myArray = (int*)malloc(n);
if(myArray != NULL)
{
if(myArray != NULL)
memset(myArray, 0, n);
{
myArray[0] = 1;
memset(myArray, 0, n);
myArray[0] = 1;
myArray[1] = 2;
myArray[1] = 2;
free(myArray);
free(myArray);
myArray = NULL;
}
myArray = NULL;

}
</highlightSyntax>
Static
Static

<highlightSyntax language=C>
int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */
int myArray2[10] = { 1, 2, 0}; /* 3..9 := 0 */
</highlightSyntax>


==[[C plus plus|C++]]==
==[[C plus plus|C++]]==