This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
int myInt; | |
signed int mySignedInt; | |
unsigned int myUnsignedInt; | |
short myShort; |
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
/* ====================================================================== */ | |
/* Double Pointers (Pointer to a Pointer) */ | |
/* ====================================================================== */ | |
// 2 levels of indirection | |
int **dblPtr; |
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main() | |
{ | |
/* ====================================================================== */ | |
/* Dynamic Memory Allocation */ | |
/* ====================================================================== */ | |
char *str = NULL; |
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
void square_num(int *num); | |
int main() | |
{ | |
/* ====================================================================== */ | |
/* Pass By Reference */ |
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
int calc_len_str(const char *str); | |
int main() | |
{ | |
char str[] = "How are you today!"; | |
int result = calc_len_str(str); | |
printf("result 1 = %d\n", result); |
This file contains hidden or 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
int main() | |
{ | |
char string1[] = "A string to be copied."; | |
char string2[50]; | |
copyStrong1(string2, string1); | |
return 0; | |
} | |
This file contains hidden or 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
int main() | |
{ | |
/* ====================================================================== */ | |
/* Pointer Arithmetic */ | |
/* ====================================================================== */ | |
/* | |
int urn[3]; | |
int *ptr1, *ptr2 |
This file contains hidden or 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
/* ====================================================================== */ | |
/* Pointers to Arrays */ | |
/* ====================================================================== */ | |
// point to first item in an array | |
char arr[] = {'a', 'b', 'c'}; | |
// apply the address operator to the first element in the array | |
char *arrPtr = &arr[0]; // without address operator you would get a value | |
// C compiler treats the array name (arr) without subscript ([]) | |
// as a pointer to the array. |
This file contains hidden or 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
/* ====================================================================== */ | |
/* Void Pointers*/ | |
/* ====================================================================== */ | |
// void* absence of a type means you are able to store any type | |
// - Often used as a return type or a parameter type of functions | |
// - You must cast it to a type when you dereference it | |
int i = 10; | |
float f = 2.34; | |
char ch = 'k'; |
This file contains hidden or 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
// * - indirection operator | |
int *pNumber = NULL, myNum = 1; | |
char *my_str = "hello"; | |
long num1 = 0L, num2 = 0L, *pNum = NULL; | |
if (pNumber == NULL) | |
printf("pNumber is currently NULL\n"); | |
pNumber = &myNum; |
NewerOlder