a little code explanation

This is a discussion on a little code explanation within the C Programming forums, part of the General Programming Boards category; i am new in c and these are my first codes. I found a code in my pdf and i ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 11:20 AM
  2. Code Explanation
    By dmkanz07 in forum C Programming
    Replies: 1
    Last Post: 03-27-2007, 09: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, 06:06 PM

Tags for this Thread


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