Thursday, 26 May 2011

C program part7

  1. What is the difference between the & and && operators and the | and || operators?
    & and | are bitwise AND and OR operators respectively. They are usually used to manipulate the contents of a variable on the bit level. && and || are logical AND and OR operators respectively. They are usually used in conditionals. 
  2. What is the difference between the -> and . operators?
    They both provide access to members of a structure or union. They differ in that -> is used when the variable is a pointer to a structure or union. The dot is used when the variable is itself the structure or union. The -> operator combines the pointer dereferencing operator with the member access operator; it is syntactic "sugar coating."
    address->city is equivalent to (*address).city.

  3. What is the symbol for the modulus operator?
    % (the percent symbol)

  4. From the standpoint of logic, what is the difference between the fragment:
    if (next < max)
    next++;
    else
    next = 0;
    
    and the fragment:
    next += (next < max)? (1):(-next);
    

    Nothing. They are different ways to express the same logic.

  5. What does the following fragment do?
    while((d=c=getch(),d)!=EOF&&(c!='\t'||c!=' '||c!='\b')) *buff++ = ++c; 

    Do the following until either the end of standard input or the variable c takes on the value of a tab, space, or backspace character: Store the character that succeeds the character stored in c into the current location pointed by buff. Then increment buff to point to the next location in memory. Meanwhile, d is assigned the same value as c and it is the value of d that is used in the comparison to EOF.

  6. Is C case sensitive (ie: does C differentiate between upper and lower case letters)?
    Yes.

  7. Specify how a filestream called inFile should be opened for random reading and writing. the file's name is in fileName.
    inFile = fopen( fileName, "r+");

  8. What does fopen() return if successful. If unsuccessful?
    Upon success fopen() returns a pointer to a filestream. Otherwise it returns the value of NULL.

  9. What is the void data type? What is a void pointer?
    The void data type is used when no other data type is appropriate. A void pointer is a pointer that may point to any kind of object at all. It is used when a pointer must be specified but its type is unknown.

No comments:

Post a Comment