Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Program 1 - 2D array and memory pointers
//gcc 5.4.0 #include <stdio.h> int main(void) { int *myPtr; int myArray[4][4]; int i; int k; int *temp; int *rowPtr[4]; //Printing column by column printf("Printing 2D array column by column: \n"); myPtr = &(myArray[0][0]); for(i = 0; i < 4; i++){ for(k = 0; k < 4; k++){ *myPtr = k; printf("%d ", *myPtr); myPtr++; } printf("\n"); } printf("\n"); //Printing row by row printf("Printing 2D array row by row: \n"); myPtr = &(myArray[0][0]); for(i = 0; i < 4; i++){ for(k = 0; k < 4; k++){ *myPtr = i; printf("%d ", *myPtr); myPtr++; } printf("\n"); } printf("\n"); //Printing using printRow method printf("Printing 2D array using printRow method: \n"); for(i = 0; i < 4; i++){ printRow(&(myArray[i][0]), 4); } printf("\n"); //Switching row 0 and row 3 for(i = 0; i < 4; i++){ rowPtr[i] = &(myArray[i][0]); } temp = rowPtr[0]; rowPtr[0] = rowPtr[3]; rowPtr[3] = temp; //Printing swapped rows printf("Printing array with row 0 and row 3 swapped: \n"); for(i = 0; i < 4; i++){ printRow(rowPtr[i], 4); } } void printRow(int *r, int nCols){ int i; int *myPtr; myPtr = r; for(i = 0; i < nCols; i++){ printf("%d ", *myPtr); myPtr++; } printf("\n"); }
run
|
edit
|
history
|
help
0
a.c
qsort
Pregunta de función cantidad de digitos
blue saver go my marshal green
if (strcmp(abb, "lol")==0 || strcmp(abb, "LOL")==0 || )
C_141113_Primos02
Bit
lab9tho
Function practice
hwkpractice