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

while initialization of array why we use a[][2] why not a[2][]...?

2142


What are the header files used in c language?

828


What is the use of void pointer and null pointer in c language?

892


What is structure in c definition?

820


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

1234


How can type-insensitive macros be created?

953


Is int a keyword in c?

760


Is c easier than java?

824


What is the purpose of sprintf?

853


What is infinite loop?

870


What does #pragma once mean?

962


If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above

866


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

3693


Why is void main used?

866


Write programs for String Reversal & Palindrome check

839