×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

void pointer as function argument in C programming

Here, we will learn how to pass a string (character pointer) in a function, where function argument is void pointer.

Consider the given example

#include <stdio.h>

//function prototype
void printString(void *ptr);

int main()
{
	char *str="Hi, there!";
	
	printString(str);
	
	return 0;
}

//function definition
void printString(void *ptr)
{
	printf("str: %s\n",ptr);
}

Output

str: Hi, there!

In this example the function parameter ptr is a void pointer and character pointer (string) str will be assigned in it and program will print the string through void pointer.


Related Tutorials



Comments and Discussions!

Load comments ↻





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