Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- char *newChar();
- int main(){
- //This will print what is returned from *newChar() - Just for testing to see if it works :)
- printf("\n%s", newChar());
- char *b = malloc(3 * sizeof(char)); //This is the local var - Must use malloc for this to work - The "3" is the size of the char array
- b = newChar(); //This sets the local var to the return of *newChar()
- printf("\n%s", b); //Print out
- }
- //This will return a pointer
- char *newChar(){
- char *a = malloc(3 * sizeof(char));
- a[0] = 'a';
- a[1] = 'b';
- a[2] = '\0';
- return a; //Since "a" was declared as a pointer, this is returning a pointer. Doing *a, would be the pointer of the pointer
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement