Hello,im a beginner in c.How do we call a function in the main function?

Recommended Answers

All 2 Replies

You simple write its name and pass it the arguments. For example:

#include <stdio.h>

int main(void) {

    /* printf *is* a function, and that's how we call all the other functions */
    printf("I am %d years old\n", 15);

    return 0;
}

Going a step further and tokenizing the function call, we get printf -- the function's name "I am %d years old\n" -- the function's first argument 15 -- the function's second argument

I hope the following code piece help:

void some_function1();
void some_function2(int);

void main()
{
	printf("in main.\r\n");
	some_function1();
	some_function2(10);
}

void some_function1()
{
	printf("in some_function1.\r\n");
}

void some_function2(int i)
{
	printf("in some_function2; parameter was %d .\r\n", i);
}

Output returned is

in main.
in some_function1.
in some_function2; parameter was 10 .
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.