The Artima Developer Community
Sponsored Link

Java Buzz Forum
Friday C Quiz: Know Your Closures

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Friday C Quiz: Know Your Closures Posted: Apr 4, 2008 6:07 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Friday C Quiz: Know Your Closures
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

You know what? This closure thing has gotten into my head. I know it's pointless and useless to think and talk about it all the time, but I can't help it.

Well, my loss is your gain. And today's Friday quiz will take you all the way back to C. Yes, old trusty C! Although ANSI C does not support closures, some C compilers provide nested function extensions that provide a limited subset of closure functionalities such as accessing variables in the outer function.

Q: Will the following C program compile and run under your C compiler? If so, what will it print?


  #include <stdio.h>
  
  int main() {
    int (*pFib)(int);
    int fib(int n) {
      return n == 0 ? 0 :
             n == 1 ? 1 :
             pFib(n - 1) + pFib(n - 2);
    }
    pFib = fib;
    printf("%d\n", pFib(6));
    return 0;
  }

Read: Friday C Quiz: Know Your Closures

Topic: Protect your online privacy when on the road by using your Home Router as a Secure Socket Proxy Previous Topic   Next Topic Topic: WordPress 2.5 Released: Will WordPress 2.5 Be The First Problem Free Major Version? ... Maybe Not

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use