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

What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?

1 Answers  


How can I increase the allowable number of simultaneously open files?

1 Answers   ABC,


Concat two string with most overlapped substring has to removeĀ  "abcd"+ "cdef" = "abcdef

6 Answers  


How can I read a directory in a C program?

2 Answers   Wipro, Bright Outdoor,


how i m write c program 1.check prime number 2.prime number series

1 Answers  






Write a program for the following series? 1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321 1234567890987654321 123456789010987654321 12345678901210987654321 1234567890123210987654321 .........1234321............ ..........123454321............ ..........12345654321............ 7 8 9 0 1 Pls............?

5 Answers  


How to print "Hi World" without using semi colon?

6 Answers   Infosys,


What is a Genralised LInked List?? Please give a detailed explation of it..

1 Answers  


Write a c program using for loop to print typical pattern if number of rows is entered by keyboard. ABCBA AB BA A A

1 Answers  


Write a Program to print this triangle: * ** * **** * ****** * ******** * ********** use two nested loops.

12 Answers   MIT, TCS,


. A database table called PERSON contains the fields NAME, BASIC and HRA. Write a computer program to print a report which employee name and total salary for those employees whose total salary is more than 10,000. Total Salary = BASIC + HRA. At the end, the program should also print the total number of employees whose total salary is more than 10,000.

1 Answers  


write a program in 'c' to find the value of p[i+1]^n.p,i,n are arguments of a macro and n is a integer

1 Answers  






Categories