Thread: a little code explanation

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    18

    a little code explanation

    i am new in c and these are my first codes.
    I found a code in my pdf and i did't understand somethings about this code.
    This is the code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #define UZUNLUK 10
    int main()
    {
        int i,sayilar [UZUNLUK];
        srand(time(NULL));
        for(i=0;i<UZUNLUK;i++)
        {
                              sayilar[i]=rand();
                              printf("sayi[%d]=%d\n",i,sayilar[i]);
                              system("pause");
        }
    }
    1) why we use #define ..... (can't we use int uzunluk=10);
    2) i can't understand anything from srand(time... line
    Last edited by orhanli1; 12-27-2010 at 02:33 AM.

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by orhanli1 View Post
    1) why we use #define ..... (can't we use int uzunluk=10);
    2) i can't understand anything from srand(time... line
    because UZUNLUK is a constant, it will not change anywhere within the program so it does not need to be a variable

    without srand(time(NULL)) the program would generate the same random numbers each time it is run
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    18
    thanks a lot.You help me so much

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Quote Originally Posted by ಠ_ಠ View Post
    because UZUNLUK is a constant, it will not change anywhere within the program so it does not need to be a variable
    because in old c-standard (C89) you cannot use variable (even const var which will not change) as array size, only define
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    18
    you are great friends thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  2. Code Explanation
    By dmkanz07 in forum C Programming
    Replies: 1
    Last Post: 03-27-2007, 08:24 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

Tags for this Thread