if function is declared as static in one source file, if I
would like to use the same function in some other source
file...is it possible....how ?

Answer Posted / vadivel t

It is possible. follow the guidelines below.

1.create a .c file called mai.c. and Its content is,

#include<stdio.h>
#include "Header.h"

static func(void);
main()
{
func();
printf("\n");
func1();
getch();
}

static func(void)
{
printf("In static fucntion");
}

2.create another file called test.c. And its content is

#include "Header.h"

func1()
{
func();
}
func()
{
printf("In normal function \n");
}

3.have a .h file called Header.h and its content is,

func1();
func();


Now main.c has a function with static key word(ie., static
func()). And its prototype and definition is available in
the same file and the same function name without static is
exist in the test.c and its prototype is there in the
Header.h

When u run the program and control hits func() in main.c it
will call the static function in the same file.

When control hits next line ie., func1() it will call the
fuction func(), which is there in the test.c file(and also
there in main.c with static key word).

Now the output will be,

In static fucntion
In normal function

Is This Answer Correct ?    9 Yes 41 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why does everyone say not to use gets?

612


Explain output of printf("Hello World"-'A'+'B'); ?

981


What is nested structure in c?

616


Which is best linux os?

570


Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......

1749






How can I list all of the predefined identifiers?

583


What's a good way to check for "close enough" floating-point equality?

632


What is pragma in c?

635


Explain continue keyword in c

590


write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);

1851


Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.

657


Explain what is the advantage of a random access file?

670


Is it possible to initialize a variable at the time it was declared?

763


Subtract Two Number Without Using Subtraction Operator

360


Can we use visual studio for c?

556