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

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 02:46 PM
  4. Some humour...
    By Stan100 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-06-2003, 10:25 PM