All articles
c

A program to explain how to pass a string to a function

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 084

  • Write a program to explain how to pass a string to a function

Program

#include <stdio.h>
 
void strings(char s1[]);
void main()
{
    char str1[30];
 
    printf("Enter string: ");
    gets(str1);
    strings(str1);
 
    printf("\n");
}
 
void strings(char s1[])
{
    puts(s1);
}

Result

Enter string: hello
hello

Comments