473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem in finding the output of c programe?

]hello guys,
i write a c programe
Expand|Select|Wrap|Line Numbers
  1. main()
  2. {
  3. extern int fun(float);
  4. int a;
  5. a=fun(3.14)
  6. printf("%d",a);
  7. getch();
  8. }int fun(aa) // ------>prob here if i write "float aa" in place of aa then it works otherwise error
  9. float=aa;//---------> if i write this statement before the int fun(aa) then this programe also show an error.not getting  "aa" a float type
  10. {
  11. return((int)aa);
  12. }
  13.  
my prob is if i write the statement "float aa ;" that meanss aa is a variable of float type & i pass this value in a function its not work shown a error.
can u plz tell the reason why it creates a problem plz explain in detail.?
May 12 '10 #1
5 1504
newb16
687 512MB
if i write the statement "float aa ;" that meanss aa is a variable of float type & i pass this value in a function
No. If you write
Expand|Select|Wrap|Line Numbers
  1. float aa;
  2. int fun(float aa)
  3. {
  4.   return aa;
  5. }
  6.  
the 'aa' in the function argument list has nothing to do with global variable aa, and within the function its argument 'aa' is used and not the global variable.
May 12 '10 #2
donbock
2,426 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. float=aa;
This is just plain wrong. I'm going to assume the equals sign is a typo in your post and isn't really in the code.

Expand|Select|Wrap|Line Numbers
  1. main();
  2.    {
  3.    extern int fun(float);
  4.    ...
  5.    }
  6.  
  7. int fun(aa)
  8.    float aa;
  9.    {
  10.    ...
  11.    }
Line 3 is a function prototype for fun, but it is located within main. This is legal, but it is contrary to typical C style conventions. Most people will put all of their function prototypes near the front of the source file before any functions are defined. Why do you include the keyword extern?

The definition of fun on lines 7-8 is an "old-style" definition. Don't do that!
May 12 '10 #3
@donbock
if i donot mention the returntype of an function in fun(aa)
then i takes by default int return type is it true?/////////////
by the way i practice on finding the output of an programe thatswhy i extern keyword i mentioned ............
May 13 '10 #4
donbock
2,426 Expert 2GB
You should use a "new-style" function definition. It really isn't that new -- this style has been in use since 1989. I'll use library function malloc as an example.

Old-style function definition:
Expand|Select|Wrap|Line Numbers
  1. void *malloc(size)
  2.    size_t size;
  3.    {
  4.    ...
  5.    }
New-style function definition:
Expand|Select|Wrap|Line Numbers
  1. void *malloc(size_t size)
  2.    {
  3.    ...
  4.    }
Function prototype:
Expand|Select|Wrap|Line Numbers
  1. void *malloc(size_t size);
Notice how similar the function prototype and new-style function definition are.
May 13 '10 #5
@donbock
but in india most of the books mention such sort of way to define the function.
actually first time i see this method of defining the function as well as declaring the function.
May 13 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matthew Robinson | last post by:
Can anybody see what is wrong with this code? apparently i have an 'empty delimiter' on the line that sets $pos - can anybody see what is wrong with it? $search_for = $_GET;...
3
by: Jerry | last post by:
I've found a problem with exec, passthru, shell_exec & system. I'm trying to run the following exec("sort -r -n -k2,2 r1.txt > r2.txt") with r1.txt being a numeric file. The file looks like...
6
by: Wescotte | last post by:
I'm writing a tiny php app that will log into our bank of america account and retrieve a file containing a list of checks that cleared the previous day. The problem I'm running into is when I...
3
by: Rob | last post by:
You can find datagrid in page by refering the form. Gatagrid is a child control of Form. Here is the code ----------------- Dim ctl As New Control For Each ctl In...
1
by: Doug | last post by:
The html below shows DataList "DiscountList" nested within DataList "EventItemList". DiscountList contains a Label control. I'm trying to find the label, using FindControl, during...
4
by: Tifer | last post by:
Hello, I'm still new to the whole .Net thing and I'm having a problem with something that should be so simple -- executing a query and returning an output parameter. It's a standard "Add"...
1
by: Empyrean | last post by:
I'm attempting to make my first program that involves file input, but I'm running into problems finding the .txt file. I placed the file inside the same folder as the rest of the project, but it...
1
by: hrubesh | last post by:
Hi, I am having a problem finding the right location of a control if it is found on a form that is on an MDI parent. On mouse click, i want to bring out a "pop up window" that will display extra...
87
by: pereges | last post by:
I have a C program which I created on Windows machine. I have compiled and executed the program on windows machine and it gives me the consistent output every time i run it. for eg. input a = 2,...
11
by: viki1967 | last post by:
Problem with output text Hi all. I have this page ASP: <!-- #include virtual="/include/conn_mysql.asp"--> <%
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.