The pointers and strings C program example, printing the string using pointer variable
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info:
To do: Displaying a string using pointer variable in C programming
To show: How to use the pointer variable to print a string in C programming
#include <stdio.h>
/* void pointer */
int func(void *thePtr);
int main(void)
{
/* assigning a string to the pointer variable */
char *theStr = "abcd1234";
/* function call */
func(theStr);
return 0;
}
int func(void *thePtr)
{
printf("%s\n", thePtr);
return 0;
}
Output example:
abcd1234
Press any key to continue . . .