Added book examples
This commit is contained in:
16
C11/array_loop_example_1.c
Normal file
16
C11/array_loop_example_1.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) // Main : Execution starts here...
|
||||
{
|
||||
// Declare variables - pre-populate the array
|
||||
int Ages[10] = {12,34,23,11,8,19,6,44,9,16};
|
||||
int i;
|
||||
|
||||
// Loop from 0 to 9 inclusive
|
||||
for ( i = 0 ; i < 10 ; i++ )
|
||||
printf ("Item %d contains value %d\n",i ,Ages[i]);
|
||||
|
||||
// Exit the application
|
||||
return 0;
|
||||
}
|
25
C11/array_loop_example_2.c
Normal file
25
C11/array_loop_example_2.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Main () - execution starts here
|
||||
int main (void)
|
||||
{
|
||||
// Declare variables
|
||||
int SampleData[10];
|
||||
int a=0;
|
||||
|
||||
// Show initial value of a
|
||||
printf ("Values in a is %d \n", a);
|
||||
|
||||
// Change an array item that IS NOT DEFINED
|
||||
SampleData[10] = 20;
|
||||
|
||||
|
||||
// See how thi affect the value in a
|
||||
printf ("Values in a is %d \n", a);
|
||||
|
||||
// Note: we can retieive this 'invalid' value - it is however 'a' we are getting
|
||||
printf ("Values in SampleData[10] is %d \n", SampleData[10]);
|
||||
|
||||
return (0); // Exit indicating sucess
|
||||
}
|
16
C11/initialise_string_example_1.c
Normal file
16
C11/initialise_string_example_1.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Main : Execution starts here...
|
||||
int main(void)
|
||||
{
|
||||
// Declare variable - pre-populate the array
|
||||
char msg[] = {'H','i',' ','W','o','r','l','d','\0'};
|
||||
|
||||
// Output with printf
|
||||
printf ("The text is: %s\n", msg);
|
||||
|
||||
puts(msg); // We could also use puts to display the string
|
||||
|
||||
return 0; // Exit the application
|
||||
}
|
15
C11/initialise_string_example_2.c
Normal file
15
C11/initialise_string_example_2.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) // Main : Execution starts here...
|
||||
{
|
||||
// Declare variable - pre-populate the array
|
||||
char msg[] = "Hello World";
|
||||
|
||||
// Output with printf
|
||||
printf ("The text is: %s\n", msg);
|
||||
|
||||
puts(msg); // We could also use puts to display the string
|
||||
|
||||
return 0; // Exit the application
|
||||
}
|
Reference in New Issue
Block a user