Thread: Difference between Automatic and Static variable

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    37

    Difference between Automatic and Static variable

    Can someone please tell me the difference between an automatic and a static variable?

    Also, what is the difference between
    Code:
    #include "stdio.h"    and         #include <stdio.h>

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    when putting them in quotes, it looks for the header where your code is saved, if it's in the less than and greater than symbol, the compiler looks for it in its include folder

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    More precisely, the search order for "file" is
    1) Project include directories. (Usually current working directory and directory of including file.)
    2) System include directories. (Specified in the compiler/project options.)

    For <file> it's
    1) System include directories.

    By convention you always use <> for foreign headers, i.e. those you didn't write for this project.

    As for automatic and static, the short version is that an automatic variable exists only as long as the function it's in is executed. A static variable lives from first execution of the function to the end of the program. (And thus, for example, preserves its value between calls to the function.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    37
    One more question...what is the difference between

    Code:
    'A'        and      "A"
    What does a single quote do compared to a double quote?

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    single quotes are for single characters and double quotes are for strings

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Do you even have a 'C' book to read?

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    17
    Actually
    "A" is a nameless const char[] of size 2.
    'A' is a nameless const char.
    Last edited by Ezzetabi; 12-18-2005 at 04:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Automatic variable
    By George2 in forum C Programming
    Replies: 9
    Last Post: 11-09-2007, 07:38 PM
  2. Automatic Counting
    By vb.bajpai in forum C++ Programming
    Replies: 5
    Last Post: 06-21-2007, 01:30 PM
  3. Static vs. Automatic Variables
    By Trekkie in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:55 PM
  4. why automatic variables are assigned with garbage values
    By srinivasg in forum C Programming
    Replies: 1
    Last Post: 11-08-2005, 07:14 AM
  5. Automatic vs. Static Duration
    By JMB in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2002, 07:16 PM