Skip to content

Instantly share code, notes, and snippets.

@viktormadarasz
Created January 6, 2018 17:01
Show Gist options
  • Save viktormadarasz/86cf80ea3e48e1c0a84363d660db9037 to your computer and use it in GitHub Desktop.
Save viktormadarasz/86cf80ea3e48e1c0a84363d660db9037 to your computer and use it in GitHub Desktop.
my own testing with passing arrays to functions
#include <iostream>
using namespace std;
void shownumberofcharsinarray(const int nElements, char text[]){
int letters = nElements-1;
cout << text << endl;
cout << "Number of letters are: " << letters << endl;
}
void shownumberofcharsinarraywithpointers (const int nElements, char *pText){
int letters = nElements-1;
cout << pText << endl;
cout << "Number of letters are: " << letters << endl;
}
int main() {
char text[]="longword";
const int nElements = sizeof(text)/ sizeof(char);
cout << "With Passing Array to Function... " << endl;
shownumberofcharsinarray(nElements, text);
cout << "With Pointers... " << endl;
shownumberofcharsinarraywithpointers(nElements, text);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment