CPP -Referenzarray

// C++ Program to demonstrate Above Approach
 
// Importing input output stream to take input
// and to display anything on the console
#include <iostream>
 
using namespace std;
 
// Method 1
// To print array elements
void print(int arr[], size_t n)
{
 
    // Iterating over elements on an array
    // using the foreach loop
    for (int element : arr) {
        // Print the elements of the array
        cout << element << " ";
    }
 
    // New line as all the desired elements are printed
    cout << endl;
}
 
// Method 2
// Main driver method
int main()
{
    // Declaring and initializing Integer array with
    // custom input entries
    int a[]{ 1, 2, 3, 4 };
 
    size_t size = sizeof(a) / sizeof(a[0]);
 
    // Calling the Method1 as created above
    // in the main) method to
    // print array elements
    print(a, size);
}





//second exsample:
#include <stdio.h>
#include <string.h>

int main ()
{
  char str1[]= "To be or not to be";
  char str2[40];
  char str3[40];

  /* copy to sized buffer (overflow safe): */
  strncpy ( str2, str1, sizeof(str2) );

  /* partial copy (only 5 chars): */
  strncpy ( str3, str2, 5 );
  str3[5] = '\0';   /* null character manually added */

  puts (str1);
  puts (str2);
  puts (str3);

  return 0;
}
Info Important