xxxxxxxxxx
#include <stdio.h>
#include <stdlib.h>
int main()
{
int * numbers = malloc(6*sizeof(int));
for(int ii = 0; ii < 6; ++ii) {
numbers[ii] = 5;
}
numbers = realloc(numbers, 7*sizeof(*numbers));
if(!numbers) {
printf("Memory allocation failed, sorry dude!\n");
exit(1);
}
numbers[6] = 7;
for(int ii = 0; ii< 7; ++ii) {
printf("%d\n", numbers[ii]);
}
free(numbers);
}
xxxxxxxxxx
// Create a list
List<string> AuthorList = new List<string>();
// Add items using Add method
AuthorList.Add("Mahesh Chand");
xxxxxxxxxx
void Append(Node *head, Node node){
Node tmp = *head;
if(*head == NULL) {
*head = node;
return;
}
while(tmp->next != NULL){
tmp = tmp->next;
}
tmp->next = node;
return;
}
xxxxxxxxxx
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
//empty list
List<int> nums = new List<int>();
//add elements to list
nums.Add(63);
nums.Add(58);
nums.Add(47);
//print list
foreach (int num in nums) {
Console.WriteLine(num);
}
}
}
Run the above C# program. The three items shall be added to the list.
Output
63
58
47