Skip to content

Instantly share code, notes, and snippets.

@Scrappers-glitch
Created March 7, 2023 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scrappers-glitch/3b3d00f90365108aac3c1f418c6d4eef to your computer and use it in GitHub Desktop.
Save Scrappers-glitch/3b3d00f90365108aac3c1f418c6d4eef to your computer and use it in GitHub Desktop.
Tests multi-dimensional references using a pointer to an array of strings.
#include <stdio.h>
int main(void*) {
const char* user = "Andrew";
const char* passwd = "ZirqfRopWpedsS0012#24";
/* create a pointer to strings (notice, we are just creating references here) */
const char* credentials[] = {user,
passwd};
/* get an element from the 1st dimension */
const char* user_cred = credentials[0]; /* or use *(credentials + 0) */
const char* passwd_cred = credentials[1]; /* or use *(credentials + 1) */
printf("%s\n", user_cred);
printf("%s\n", passwd_cred);
/* get an element from the 2nd dimension */
const char user_cred_c0 = user_cred[0];
const char user_cred_c1 = credentials[0][1];
const char user_cred_c2 = *(user_cred + 2);
const char user_cred_c3 = *(*(credentials + 0) + 3);
const char user_cred_c4 = *(*(credentials + 0) + 4);
const char user_cred_c5 = *(*(credentials + 0) + 5);
printf("%c", user_cred_c0);
printf("%c", user_cred_c1);
printf("%c", user_cred_c2);
printf("%c", user_cred_c3);
printf("%c", user_cred_c4);
printf("%c", user_cred_c5);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment