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 ?

Answers were Sorted based on User's Feedback



if function is declared as static in one source file, if I would like to use the same function in s..

Answer / lakshman

using function pointer in main.c which holds address of
static function in the same file. But function pointer can
be used in other files.

Is This Answer Correct ?    26 Yes 5 No

if function is declared as static in one source file, if I would like to use the same function in s..

Answer / 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

More C Interview Questions

how can i get the output 54321 4321 321 21 1 in c programming........???? pls help......

10 Answers   Infosys,


write a c program to store and print name,address,roll.no of a student using structures?

7 Answers  


Program to display given 3 integers in ascending order

1 Answers   N Tech,


What is use of pointer?

0 Answers  


What does static mean in c?

1 Answers  






1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.

0 Answers  


"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above

0 Answers  


HOW TO FIND OUT THE RREVERS OF A GIVEN DIGIT NUMBER IF IT IS INPUT THROUGH THE KEYBORD BY USING C LANGUAGE

3 Answers   Wipro,


What is the difference between single charater constant and string constant?

0 Answers  


How are structure passing and returning implemented?

0 Answers  


program to get the remainder and quotant of given two numbers with out using % and / operators?

10 Answers   College School Exams Tests, IBM,


What are the advantages of using new operator as compared to the function malloc ()?

0 Answers   NIIT,


Categories