ADVERTISEMENT
ADVERTISEMENT

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

ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.