Homechevron_rightEngineeringchevron_rightComputer Sciencechevron_rightData Structurechevron_rightConsider arr [ ] is an array in C language. What will be the effect of...

Consider arr [ ] is an array in C language. What will be the effect of...

  • Q. Consider arr [ ] is an array in C language. What will be the effect of "arr++;" ?
  • filter_dramaExplanation
    Answer is : D

    Answer: Option 4

    Explanation

    Consider the following example 

    #include <stdio.h>
    int main()
    {
           int arr[10] = {1, 2, 3, 4, 5, 6, 7};

           arr++;
           return 0;
    }

    Here arr++; mean that

    arr = arr + 1 ;

    which is wrong we can not change the base address of an array and it will generate an error.
    another way to do that is by using pointers.

    #include <stdio.h>
    int main()
    {
           int arr[10] = {1, 2, 3, 4, 5, 6, 7};

           int *p = arr;

           p++;
           return 0;
    }

    Here int *p = arr; new pointer variable will be created which will start pointing to the first element of the array.

    and p++; will cause the pointer to start pointing to the next element of the array.

Discussion

    No one started the discussion yet. Break the ice and start the conversation.
    Please Login to be part of the discussion.

Similar Questions

  • 1. Which of the following is illegal declaration in C language?
  • filter_dramaExplanation
    Answer is : D

    Concept –

    Option_1: A valid declaration in C.

    char *str is a single value which is a pointer to a character. When used as a string in C, it is implied that subsequent characters of the string are stored in subsequent memory addresses, until the end of the string which is marked with a NULL.

    Option_2: A valid declaration in C.

    Char str[20] is an array of maximum 20 characters. It is similar to char *str except that there is no requirement that the last character in the array be null.

    Option_3A valid declaration in C.

    char str[40] is an array of maximum 40 characters. It is similar to char *str except that there is no requirement that the last character in the array be null.

    Option_4: Not a valid declaration in C.

    char[] str is a declaration in Java, but not in C.
  • 2. Which of the following statements is INCORRECT with respect to a binary tree?
  • filter_dramaExplanation
    Answer is : D

    Answer: Option 4

    Concept

    Full Binary Tree

    A full binary tree is a binary tree in which each node has exactly two or 0 children.

    Complete Binary Tree:

    A complete binary tree is a binary tree in which

    1. except last level tree is completely filled.
    2. The last level is filled from left to right.

    Perfect Binary Tree

    A perfect binary tree is a binary tree in which

    1. all interior node or internal nodes has 2 children.
    2. all leaves are at the same level.

    Balanced Binary Tree

    A Balanced Binary tree is a binary tree in which at any node height of the left sub tree and right sub tree do not differ by more than 1.

  • 3.

    What will be the output of the following C program:(consider int is of 4 bytes and array (arr) starting address is 2000 in decimal )

    #include <stdio.h>
    int main()
    {
           int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
           printf("%u\n",(arr+1));
           printf("%u",(&arr + 1));
           return 0;
    }
  • filter_dramaExplanation
    Answer is : C

    Answer: Option 3

    Explanation

    - arr denote the Base address of the array.

    - &arr will not work the same way as some of you think.

    printf("%ld\n",arr+1);

    - In the First printf ; arr +1 , addition of 1 resulted in an address increment of 1 int data size hence 2000 + 4 = 2004 will be printed

    printf("%ld",(&arr + 1));
    - &arr will return a pointer to the whole array of 10 int, addition of 1 resulted in an address with an increment of 4 x 10 = 40 and hence 2040 will be printed in next line.

    Hence Option 3 is the correct answer.

  • 4.

    A binary tree T has n leaf nodes, the number of nodes of degree 2 in T is:

  • filter_dramaExplanation
    Answer is : B

    In an "m-ary" tree. the number of total nodes (N) is given by

    N=mi + 1  ----(1)

    Where,

    i: Number of internal nodes

    Also, in a tree, N=i + L   ----(2)

    Where,

    L=number of leaf nodes

    Here m=2

    From equation (1) and equation (2);

    N = 2i + 1

    2i + 1 = i + L

    L = i + 1

    The number of leaves are 1 plus the number of internal nodes in binary tree.

    Here, given L=n, substitute above and we will get,

    i = L - 1

  • 5.

    The for statement 

    for(expr; expr; expr3) is equivalent to

  • filter_dramaExplanation
    Answer is : C

    While loop:

    In the while loop, the expression is evaluated.  If it is non-zero, the statement is executed and the expression is re-evaluated. This cycle continues until expression becomes zero, at which point execution resumes after the statement. 

    For loop:

    In the case of for loop, expris an assignment or function call, expr2 is a relational expression while expr3 is also an assignment or function call. The for loop basically assigns the value to a variable using expr1, expr2 is used to evaluate the expression, and expris used to modify the value of expr2 so that the terminating condition is reached.

    This functionality can be achieved using the while statement as listed in option 3.

Data StructureTopics

leaderboardLeaderboard
  • Rahul Kumar

    191 Points

  • VIKRAM JEET

    54 Points

  • GEETHIKA CHOWDARY

    53 Points

  • sunita saini

    52 Points

  • Zain

    49 Points