how can I write code to test a[100];

This is a discussion on how can I write code to test a[100]; within the C Programming forums, part of the General Programming Boards category; I write some codes as follows: Code: int main() { int a[2]; a[0] = 1; a[1] = 1; return 0; ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    168

    how can I write code to test a[100];

    I write some codes as follows:
    Code:
    int main()
    {
      int a[2];
      a[0] = 1;
      a[1] = 1;
      
      return 0;
    }
    If my printing code is as follow:
    Code:
    printf("%d\n",a[100]); //a[100] not defined
    The result is "segmentation fault";

    how can I write code to test a[100];
    (I means if a[100] is defined, print
    if a[100] is not defined, printf("a[100] is not defined.\n")

    how can I carry out?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to write a C code that evaluates 7, 7, 7, 1 = 100
    By filanfistan in forum C Programming
    Replies: 8
    Last Post: 10-21-2005, 07:37 AM
  2. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 12:55 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Some humour...
    By Stan100 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-06-2003, 09:25 PM

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