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 make a program in c to print 'Hello' without using semicolon in the code?

9 Answers   C DAC, Practical Viva Questions,


if we take a number as a char then can we manipulate(add, subtract) on this number

2 Answers  


What is a macro?

0 Answers  


Why isn't it being handled properly?

0 Answers  


What is nested structure with example?

0 Answers  






please give me some tips for the placement in the TCS.

0 Answers   TCS,


What will be the output of following program #include main() { int x,y = 10; x = y * NULL; printf("%d",x); }

1 Answers  


what is the difference between #include<stdio.h> and #include"stdio.h" ?

6 Answers   TCS,


how to capitalise first letter of each word in a given string?

0 Answers  


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

0 Answers  


Write a C program to convert an integer into a binary string?

1 Answers  


main() { int a = 65; printf(“%d %o %x”,a,a,a); } Output 65 101 41 Please explain me.How it is coming like that?

3 Answers   Excel,


Categories