Difference between Automatic and Static variable

This is a discussion on Difference between Automatic and Static variable within the C++ Programming forums, part of the General Programming Boards category; Can someone please tell me the difference between an automatic and a static variable? Also, what is the difference between ...

  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,893
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    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 03: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, 06: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, 01:55 PM
  4. why automatic variables are assigned with garbage values
    By srinivasg in forum C Programming
    Replies: 1
    Last Post: 11-08-2005, 06:14 AM
  5. Automatic vs. Static Duration
    By JMB in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2002, 07:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21