GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Tech FAQs  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 3 of 255    Print  
Why doesn't C have nested functions?

  
Total Answers and Comments: 6 Last Update: April 20, 2007   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: priti
 
#include<stdio.h>

int add(int a,int b)
{
    int c=3;
    int d=a+b;

    int addToC(int c, int d )
    {
        printf("This is addToC.....n");
        return(c+d);
    }
    return(addToC(c,d));

}

int main()
{
    printf(" Addition   %d n" ,add(1,2));
    return 0;

}



Above answer was rated as good by the following members:
gunturi.prabhakar
August 13, 2005 12:02:57   #1  
hariharan        

RE: Why doesn't C have nested functions?
we does not have nested functions in c because we use concept of friend function 

 
Is this answer useful? Yes | No
August 26, 2005 09:52:36   #2  
satish        

RE: Why doesn't C have nested functions?
We don't have anything like friend function in C it is in C++
 
Is this answer useful? Yes | No
July 31, 2006 01:39:59   #3  
praveena        

RE: Why doesn't C have nested functions?

since it has friend function it doesnt have nested function


 
Is this answer useful? Yes | No
November 17, 2006 14:21:44   #4  
s.vamsikrishna        

RE: Why doesn’t C have nested functions?
c does not have nested functions because c doesnot not support encapsulation.in c each and every function is independent to each other and performs its assigned task separately
 
Is this answer useful? Yes | No
January 18, 2007 01:22:42   #5  
priti        

RE: C Has Nested FunctionWhy doesn't C have nested functions?
#include<stdio.h>

int add(int a,int b)
{
    int c=3;
    int d=a+b;

    int addToC(int c, int d )
    {
        printf("This is addToC.....n");
        return(c+d);
    }
    return(addToC(c,d));

}

int main()
{
    printf(" Addition   %d n" ,add(1,2));
    return 0;

}


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
April 20, 2007 06:55:31   #6  
govardhan        

RE: answerWhy doesn't C have nested functions?
It's not trivial to implement nested functions such that they have the proper access to local variables in the containing function(s), so they were deliberately left out of C as a simplification. (gcc does allow them, as an extension.) For many potential uses of nested functions (e.g. qsort comparison functions), an adequate if slightly cumbersome solution is to use an adjacent function with static declaration, communicating if necessary via a few static variables. (A cleaner solution, though unsupported by qsort, is to pass around a pointer to a structure containing the necessary context.)

 


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape