Home » Uncategorized » Pointers and String in C

Pointers and String in C

Pointers and strings can be used variably. Following is a demo tutorial showcasing the difference between pointers and strings in C.

This tutorial is meant for beginners and has a very simple syntax to try.

#include <stdio.h>

int main(void) {
	char *message = "hello";
	char *p;

	p = message;
	printf("string in p : %s\n", p);

	// Now we will try to update the string in p
	p = "world";
	printf("updated string in p : %s\n", p);

	// same you can't do with static string which can be defined as

	// char message[] = "hello";
	// char p[10];
	// p = message;
	// this will give error;
	// or p = "world" is not possible.

	// hence we need to use pointers;
	
	return 0;
}

We hope this tutorial is of help. In case you have any other suggestions or questions, do let us know in the comments!


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment