Passing Structure Char Pointer to Function in C programming language

Using char pointer variable as structure member is useful but how will you pass the variable to a function? This C programming tutorial will show you how you can do this.

Passing structure Char pointer to a function in C programming language is done like passing any other data types. For example, if we want to pass an integer variable then we would write printMessage(int x), where the argument is int x. Similarly to pass a char pointer variable we simply construct function like printMessage(char* msg).

The following C code demonstrates this with structure.


Here, we have a structure APP_DATA which has a member message which is a type char pointer. In the main, we have created a structure variable appData. Then we have assigned “Hello World!\n” string to the member. Next we have called the printMessage function and passed into it the appData.message variable. Finally, we have implemented the printMessage() function and to pass the structure char pointer we have indicated the input argument type which is char*.

What do you think?

9 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Leave a Reply

Your email address will not be published. Required fields are marked *

What is Callback function in MPLAB Harmony

Dot Vs Arrow Operator and Char pointer in Structure C programming tutorial