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

What are register variables in c?

547


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

1267


Tell me what are bitwise shift operators?

632


What functions are in conio h?

635


What is the difference between test design and test case design?

1542






What is the use of bitwise operator?

664


Explain how can I open a file so that other programs can update it at the same time?

570


What is the general form of #line preprocessor?

558


How to explain the final year project as a fresher please answer with sample project

451


What is the difference between #include

and #include “header file”?

527


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

626


Can we assign integer value to char in c?

595


Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given

2480


What is the use of the function in c?

573


What is signed and unsigned?

617