C - Structure with Character Pointers.


IncludeHelp 19 September 2016

In this code snippet/program/example we will learn how to use character pointers with structure in c programming language?

In this example we will declare two character pointers to store strings within the structure, assign values to them without using strcpy() function of string.h (because we can assign string directly to the character pointer) and print the value of assigned character pointers.

C Code Snippet - Structure with Character Pointers

/*C - Structure with Character Pointers. */

#include<stdio.h>

//structure declaration
struct temp{
	char *fname;
	char *lname;
};

int main(){
	struct temp T;
	T.fname="Mike";
	T.lname="Thomas";
	
	printf("First Name: %s\n",T.fname);
	printf("Last  Name: %s\n",T.lname);
	
	return 0;	
}

    First Name: Mike
    LastName: Thomas



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.