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
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 |
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 |
IS Doon college of Engn.. has good faculty
Write a program to identify if a given binary tree is balanced or not.
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none
Write a program to find factorial of a number using recursive function.
Explain the difference between malloc() and calloc() in c?
Explain what is dynamic data structure?
what is the output of the following program? main() { int c[]={2,8,3,4,4,6,7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf("%d",*c); ++q; } for(j=0;j<5;j++) { printf("%d",*p); ++p; } }
What are extern variables in c?
hi , please send me NIC written test papers to sbabavalli@gmail.com
Explain pointer. What are function pointers in C?
code for quick sort?
How is pointer initialized in c?