1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

100 Multiple choice questions in C

Discussion in 'C' started by coderzone, Apr 2, 2006.

  1. MultipleChoiceInC

    MultipleChoiceInC New Member

    Joined:
    May 4, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    void func(void){
    printf("func");
    ((char*) 0)=0;

    }
    The function func(), triggers memory fault. Which one explains why "func" may NOT be printed before the crash?
    Choice 1
    Insufficient information to determine why the output fails.

    Choice 2
    printf() expects more than one argument. As only one argument is given, crash may actually occur inside printf().

    Choice 3
    Output stream is buffered and may not be flushed before the crash occurs. (Ans--?)

    Choice 4
    printf() always buffers output until a newline character appears in buffer. Since no newline was present in the format string, nothing is printed.
     
  2. MultipleChoiceInC

    MultipleChoiceInC New Member

    Joined:
    May 4, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    How does variable definition differ from variable declaration?

    Choice 1
    Definition allocates storage for a variable, but declaration only informs the compiler as to the variable's type.

    Choice 2
    Declaration allocates storage for a variable, but definition only informs the compiler as to the variable's type.

    Choice 3
    Variables may be defined many times, but may be declared only once.(Ans --?)

    Choice 4
    Variable definition must precede variable declaration.

    Choice 5
    There is no difference in C between variable declaration and variable definition.
     
  3. MultipleChoiceInC

    MultipleChoiceInC New Member

    Joined:
    May 4, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Which one of the following is a true statement about pointers?

    Choice 1
    Pointer arithmetic is permitted on pointers of any type.(Ans-- ??)

    Choice 2
    A pointer of type void * can be used to directly examine or modify an object of any type.

    Choice 3
    Standard C mandates a minimum of four levels of indirection accessible through a pointer.

    Choice 4
    A C program knows the types of its pointers and indirectly referenced data items at runtime.

    Choice 5
    Pointers may be used to simulate call-by-reference.
     
  4. MultipleChoiceInC

    MultipleChoiceInC New Member

    Joined:
    May 4, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    unsigned int p=0;
    (p^p)||p++||++p||p++;

    What is the value of the variable "p" after executing the above code?

    Choice 1
    1

    Choice 2
    2 (Ans--??)

    Choice 3
    3

    Choice 4
    The value is undefined because "p" is initialized to 0.
     
  5. MultipleChoiceInC

    MultipleChoiceInC New Member

    Joined:
    May 4, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Which is functionally equivalent of arithmetic right shift of signed int p by 2 and is portable?

    Choice 1
    p / 4 (Ans---??)

    Choice 2
    p / 2

    Choice 3
    p >>> 2

    Choice 4
    p >> 2

    Choice 5
    p > 0 ? p >> 2 | 1 << sizeof(p) * 8 - 1 : p >> 2
     
  6. MultipleChoiceInC

    MultipleChoiceInC New Member

    Joined:
    May 4, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    char var1[10];
    char var2[5]="Forum";
    strcpy(var1,var2);
    printf("%s,%s",var1,var2);
    What is the output of the above code?

    Choice 1
    No output as it is array overflow error.

    Choice 2
    "Forum Forum"

    Choice 3
    Results undefined. Depending on platform, code may cause access violation.

    Choice 4
    Compilation error because string pointers can be initialized with a string literals only
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    The freeing of a null pointer will cause a program crash.
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Checkout the function signature and that would help
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    strcat(str,"\?");
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    By definition, an lvalue is the storage space indirectly referenced by a pointer.
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    I am not sure what does variable definition means but it should be some thing like defining the class.
     
  13. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    My answer would be The null pointer is the pointer in which the value is zero (0). but then its debatable.
     
  14. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Check with your compiler
     
  15. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    x / 4
     
  16. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    "Hello Hello"
    but there should be a comma (,) in between both the hello's
     
  17. psapikas

    psapikas New Member

    Joined:
    Aug 1, 2007
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Mathematician
    Location:
    Athens
    I think this result should be printed if the second array was defined as: var2[6]
     
  18. brajrajsingh

    brajrajsingh New Member

    Joined:
    Jan 18, 2008
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
  19. MultipleChoiceInC

    MultipleChoiceInC New Member

    Joined:
    May 4, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Re: 100 Multiple choice questions in C (New Question?)

    char buf[50]="Hello World";
    char *ptr=buf+5;

    What's the right way to copy 15 bytes from the location pointed by "ptr" to the beginning of "buf"?
    Choice 1
    memmove( buf, ptr, 15 ); (ans)

    Choice 2
    Illegal memory access because it will read memory past the end of the string.

    Choice 3
    strncpy( buf, ptr, 15 );

    Choice 4
    Cannot be done because the source and destination overlap.

    Choice 5
    memcpy( buf, ptr, 15 );
     
  20. MultipleChoiceInC

    MultipleChoiceInC New Member

    Joined:
    May 4, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Re: 100 Multiple choice questions in C (Ask New Questions?)

    struct node {
    int id;
    int lengh;
    struct node *next;
    struct node *prev;
    unsighed char data[1];
    }

    Considering struct node, an aggregate type defined above, which one of the following might explain the declaration of its peculiar member data?
    Choice 1

    There is no difference between character unsigned char data and array unsigned char data [1] since each allocates only a single byte. Identical operations can be performed on both quantities. The choice was one of preference.
    Choice 2

    The programmer is declaring a bit field called data, which consists of only a single bit. struct node probably represents some hardware device.
    Choice 3

    data is probably used in conjunction with length and malloc() to create objects of variable size. struct node is essentially a header for an object of indeterminate size.
    Choice 4

    The information provided by the definition of struct node is insufficient to formulate a guess about the purpose of the member data or its strange declaration. (Ans)
    Choice 5

    The programmer has made a typo. If the programmer had intended to allocate only a single byte, the data would have been declared as unsigned char data instead.
     

Share This Page