Created
January 6, 2018 17:01
-
-
Save viktormadarasz/86cf80ea3e48e1c0a84363d660db9037 to your computer and use it in GitHub Desktop.
my own testing with passing arrays to functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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