Thread: queries regarding address allocation

  1. #1
    Registered User
    Join Date
    Aug 2016
    Posts
    6

    queries regarding address allocation

    taking the example of the following code snippet

    int marks;
    ...........
    scanf("%d",&marks);


    1-which statement allocates address and memory to the integer variable marks?
    2-does the aforementioned allocation assigns 5 consecutive addresses to each 5 characters of the variable?
    3-if so happens then how is the value being assigned to the variable, alloted the addresses possesed by the variable because the memory requirement of the assigned values could be >or< than that of the variable it is being assigned to.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    1-which statement allocates address and memory to the integer variable marks?
    int marks;
    2-does the aforementioned allocation assigns 5 consecutive addresses to each 5 characters of the variable?
    No.
    3-if so happens then how is the value being assigned to the variable, alloted the addresses possesed by the variable because the memory requirement of the assigned values could be >or< than that of the variable it is being assigned to.
    The length of the variable's name doesn't affect how many bytes are "allocated" to the variable. The variable type is the determining factor for how much memory is allocated for the variable.

    Jim

  3. #3
    Registered User
    Join Date
    Aug 2016
    Posts
    6
    thnks sir...but then in that case the variable marks should be allocated 2 bytes of memory being an integer and if we make the variable store a 5-digit integer (requiring 5*2=10bytes memory) then how would each digit be allocated memory?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    thnks sir...but then in that case the variable marks should be allocated 2 bytes of memory being an integer
    You are not storing digits in memory, you are storing a value. A signed int can hold values of at least -32767 to 32767, but usually a much larger value can be accommodated with most modern operating systems. For example on my system an int has a maximum of 2,147,483,647.

    Jim

  5. #5
    Registered User
    Join Date
    Aug 2016
    Posts
    6
    sir if understood it correctly you mean in case of reading input data a value is being alloted to the starting address of the variable and not an integer number.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Macros Queries
    By Mr.Lnx in forum C Programming
    Replies: 19
    Last Post: 03-20-2013, 01:40 PM
  2. some queries on arrays
    By jackson6612 in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2011, 04:33 AM
  3. two small queries
    By jackson6612 in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2011, 04:30 AM
  4. malloc() & address allocation
    By santechz in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 09:08 AM
  5. Replies: 7
    Last Post: 12-10-2004, 08:18 AM

Tags for this Thread