Explained C Aptitude Interview Questions Series-4

Here are Third batch of frequently asked C aptitude questions & these questions have proper answers given so mnc team suggest you should go over these Apptitude questions before your job job interview


If u haven`t read C aptitude questions#1 & #2 & #3 in this excellent series then please do so before continuing


17. Why do programmers suggest not to use gets()?


A: Unlike fgets(), gets() cannot be told the size of the buffer it's to read into, so it cannot be prevented from overflowing that buffer. As a general rule, always use fgets().


18. Why is it that errno contain ENOTTY after a call to printf()?


A: Many implementations of the stdio package adjust their behavior slightly if stdout is a terminal. To make the determination, these implementations perform some operation which happens to fail (with ENOTTY) if stdout is not a terminal. Although the output operation goes on to complete successfully, errno still contains ENOTTY. (Note that it is only meaningful for a program to inspect the contents of errno after an error has been reported; errno is not guaranteed to be 0 otherwise.)


19. What is the difference between fgetpos/fsetpos & ftell/fseek? What are fgetpos() & fsetpos() good for exactly?


A: ftell() & fseek() use type long int to represent offsets (positions) in a file, & may therefore be limited to offsets of about 2 billion (2**31-1). The newer fgetpos() & fsetpos() functions, on the other hand, use a special typedef, fpos_t, to represent the offsets. The type behind this typedef, if chosen appropriately, can represent arbitrarily large offsets, so fgetpos() & fsetpos() can be used with arbitrarily huge files. fgetpos() & fsetpos() also record the state associated with multibyte streams.


20. How can I flush pending input so that a user's typeahead isn't read at the next prompt? Will fflush(stdin) work?


A: fflush() is defined only for output streams. Since its definition of "flush" is to complete the writing of buffered characters (not to discard them), discarding unread input would not be an analogous meaning for fflush on input streams.


There is no standard way to discard unread characters from a stdio input stream, nor would such a way necessarily be sufficient, since unread characters can also accumulate in other, OS-level input buffers. You may be able to read & discard characters until \n, or use the curses flushinp()function, or use some system-specific technique.


21. I'm trying to update a file in place, by using fopen mode "r+", reading a certain string, & writing back a modified string, but it's not working.


A: Be sure to call fseek before you write, both to seek back to the beginning of the string you're trying to overwrite, & because an fseek or fflush is always required between reading & writing in the read/write "+" modes. Also, remember that you can only overwrite characters with the same number of replacement characters, & that overwriting in text mode may truncate the file at that point.


22. How can I redirect stdin or stdout to a file from within a program?


A: Use freopen()


23. Once I've used freopen(), how can I get the original stdout (or stdin) back?


A: There isn't a good way. If you need to switch back, the best solution is not to have used freopen() in the first place. Try using your own explicit output (or input) stream variable, which you can reassign at will, while leaving the original stdout (or stdin) undisturbed.


It is barely possible to save away information about a stream before calling freopen(), such that the original stream can later be restored, but the methods involve system-specific calls such as dup(), or copying or inspecting the contents of . a FILE structure, which is exceedingly nonportable & unreliable.


24. How can I arrange to have output go two places at once, e.g. to the screen & to a file?


A: You can't do this directly, but you could write your own printf variant which printed everything twice.


25. How can I read a binary data file properly? I'm occasionally seeing 0x0a & 0x0d values getting garbled, & I seem to hit EOF prematurely if the data contains the value 0x1a.


A: When you're reading a binary data file, you should specify "rb" mode when calling fopen(), to make sure that text file translations do not occur. Similarly, when writing binary data files, use "wb".


+Some Great DBMS aptitude Questions


+Exhaustive collection of Operating System Concepts


+All the C apptitude questions You want


READ ANSWER and EXPLANATION

C Aptitude Interview Questions Explained Series-1


Here are some frequently asked C aptitude questions & these questions have proper answers given so mnc team suggest you should go over these Apptitude questions before your job job interview.


Declarations & Initializations:


Q How do you decide that integer type to use?


A: If you might need large values (above 32,767 or below -32,767), use long. Otherwise, if space is very important (i.e. if there are large arrays or many structures), use short. Otherwise, use int. If well-defined overflow characteristics are important & negative values are not, or if you want to steer clear of sign- extension problems when manipulating bits or bytes, use one of the corresponding unsigned types. (Beware when mixing signed & unsigned values in expressions, though.) Although character types (especially unsigned char) can be used as "tiny" integers, doing so is sometimes more trouble than it's worth, due to unpredictable sign extension & increased code size.


A similar space/time tradeoff applies when deciding between float & double. None of the above rules apply if the address of a variable is taken & must have a particular type. If for some reason you need to declare something with an *exact* size (usually the only good reason for doing so is when attempting to conform to some externally-imposed storage layout, but see question 20.5), be sure to encapsulate the choice behind an appropriate typedef.


Q What should the 64-bit type on a machine that can support it?


A: The forthcoming revision to the C Standard (C9X) specifies type long long as effectively being at least 64 bits, & this type has been implemented by a number of compilers for some time. (Others have implemented extensions such as __longlong.) On the other hand, there's no theoretical reason why a compiler couldn't implement type short int as 16, int as 32, & long int as 64 bits, & some compilers do indeed choose this arrangement.


Q What is the best way to declare & define global variables & functions?


A: First, though there can be many "declarations" (& in many translation units) of a single "global" (strictly speaking, "external") variable or function, there must be exactly one "definition". (The definition is the declaration that actually allocates space, & provides an initialization value, if any.) The best arrangement is to place each definition in some relevant .c file, with an external declaration in a header (".h") file, that is #included wherever the declaration is needed. The .c file containing the definition should also #include the same header file, so that the compiler can check that the definition matches the declarations. This rule promotes a high degree of portability: it is consistent with the requirements of the ANSI C Standard, & is also consistent with most pre-ANSI compilers & linkers. (Unix compilers & linkers typically use a "common model" that allows multiple definitions, as long as at most one is initialized; this behavior is mentioned as a "common extension" by the ANSI Standard, no pun intended. A few very odd systems may require an explicit initializer to distinguish a definition from an external declaration.) It is possible to use preprocessor tricks to arrange that a line like DEFINE(int, i); need only be entered once in one header file, & turned into a definition or a declaration depending on the setting of some macro, but it's not clear if this is worth the trouble. It's especially important to put global declarations in header files if you want the compiler to catch inconsistent declarations for you. In particular, never place a prototype for an external function in a .c file: it wouldn't generally be checked for consistency with the definition, & an incompatible prototype is worse than useless.


Q What does extern mean in a function declaration?


A: It can be used as a stylistic hint to indicate that the function's definition is probably in another source file, but there is no formal difference between extern int f(); & int f();


Q What is the auto keyword good for?


A: Nothing; it's archaic.


Q Define a linked list & tried typedef struct { char *item; NODEPTR next; } *NODEPTR; but the compiler give to error messages. Can't a structure in C contain a pointer to itself?


A: Structures in C can certainly contain pointers to themselves; the discussion & example in section 6.5 of K&R make this clear. The problem with the NODEPTR example is that the typedef has not been defined at the point where the "next" field is declared. To fix this code, first give the structure a tag ("struct node"). Then, declare the "next" field as a simple "struct node *", or disentangle the typedef declaration from the structure definition, or both. One corrected version would be struct node { char *item; struct node *next; }; typedef struct node *NODEPTR; & there are at least three other equivalently correct ways of arranging it. A similar problem, with a similar solution, can arise when attempting to declare a pair of typedef'ed mutually referential structures.


Q How do you declare an array of N pointers to functions returning pointers to functions returning pointers to characters?


A: The first part of this question can be answered in at least three ways:


1. char *(*(*a[N])())(); 2. Build the declaration up incrementally, using typedefs: typedef char *pc; /* pointer to char */ typedef pc fpc(); /* function returning pointer to char */ typedef fpc *pfpc; /* pointer to above */ typedef pfpc fpfpc(); /* function returning... */ typedef fpfpc *pfpfpc; /* pointer to... */ pfpfpc a[N]; /* array of... */ 3. Use the cdecl program, that turns English into C & vice versa: cdecl> declare a as array of pointer to function returning pointer to function returning pointer to char char *(*(*a[])())() cdecl can also explain complicated declarations, help with casts, & indicate that set of parentheses the arguments go in (for complicated function definitions, like the one above). Any good book on C should explain how to read these complicated C declarations "inside out" to understand them ("declaration mimics use"). The pointer-to-function declarations in the examples above have not included parameter type information. When the parameters have complicated types, declarations can *really* get messy.


Q How you declare a function that can return a pointer to a function of the same type? you will building a state machine with one function for each state, each of that returns a pointer to the function for the next state. But you can't find a way to declare the functions.


A: We can't quite do it directly. Either have the function return a generic function pointer, with some judicious casts to adjust the types as the pointers are passed around; or have it return a structure containing only a pointer to a function returning that structure.


Q Some compiler is complaining about an invalid redeclaration of a function, but you only define it once & call it once.


A: Functions that are called without a declaration in scope (perhaps because the first call precedes the function's definition) are assumed to be declared as returning int (& without any argument type information), leading to discrepancies if the function is later declared or defined Or. Non-int functions must be declared before they are called. Another possible source of this problem is that the function has the same name as another one declared in some header file.


Q. What is the right declaration for main()? Is void main() correct?


A: But no, it's not correct


Q. What are you allowed to assume about the initial values of variables that are not explicitly initialized? If global variables start out as "zero", is that good enough for null pointers & floating-point zeroes?


A: Uninitialized variables with "static" duration (that is, those declared outside of functions, & those declared with the storage class static), are guaranteed to start out as zero, as if the programmer had typed "= 0". Therefore, such variables are implicitly initialized to the null pointer (of the correct type; see also section 5) if they are pointers, & to 0.0 if they are floating-point. Variables with "automatic" duration (i.e. local variables without the static storage class) start out containing garbage, unless they are explicitly initialized. (Nothing useful can be predicted about the garbage.) Dynamically-allocated memory obtained with malloc() & realloc() is also likely to contain garbage, & must be initialized by the calling program, as appropriate. Memory obtained with calloc() is all-bits-0, but this is not necessarily useful for pointer or floating-point values


 


We have Featured several C aptitude questions in march & quntitative questions also so do check them out.


READ ANSWER and EXPLANATION

Quantitative Aptitude Question 6 (Questions Set 2)

The following figure depicts three views of a cube. Based on this, answer questions

Free Image Hosting at www.ImageShack.us
10. The number on the face opposite to the face carrying 1 is _______ .
11. The number on the faces adjacent to the face marked 5 are _______ .
12. Which of the following pairs does not correctly give the numbers on the opposite faces.
(1) 6,5 (2) 4,1 (3) 1,3 (4) 4,2

Answer
5
11. Answer
1,2,3 & 4
12. Answer
B


READ ANSWER and EXPLANATION

Sql Aptitude questions excellent collection


Sql Aptitude Very neat collection


 Q. What command is used to create a table by copying the structure of another table?
Answer :
   CREATE TABLE .. AS SELECT command
Explanation : 
To copy only the structure, the WHERE clause of the SELECT command should
contain a FALSE statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE
WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition
will be copied to the new table. 
 
Q. What will be the output of the following query?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'),
'AN', '**'),'*','TROUBLE') FROM DUAL;
   TROUBLETHETROUBLE 
 
Q. What will be the output of the following query?
SELECT  DECODE(TRANSLATE('A','1234567890','1111111111'), '1','YES', 'NO' );
Answer :
   NO.
Explanation : 
The query checks whether a given string is a numerical digit. 
 
Q. What does the following query do?
SELECT SAL + NVL(COMM,0) FROM EMP;
   This displays the total salary of all employees. The null values in the commission
column will be replaced by 0 & added to salary.


Q. What is the difference between TRUNCATE & DELETE commands? 
TRUNCATE is a DDL command whereas DELETE is a DML command. Hence
DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back.
WHERE clause can be used with DELETE & not with TRUNCATE.


For more Sql Questions we suggest you come back to the original site(mncplacement)& check out more sql questions asked in 2007/2008.


More C/C++ Aptitude Questions


More Excellent SQL QUESTIONS collection


 


READ ANSWER and EXPLANATION

Top C aptitude questions (updated 2008)


Aptitude Questions on C Programming language



      Q Does C have boolean variable type?


      No, C does not have a boolean variable type. One can use ints, chars, #defines or enums to achieve the same in C.


      #define TRUE 1
      #define FALSE 0
      enum bool {false, true};


      An enum may be good if the debugger shows the names of enum constants when examining variables.
   Q Where may variables be defined in C?


      Outside a function definition (global scope, from the point of definition downward in the source code). Inside a block before any statements other than variable declarations (local scope with respect to the block).
   
   Q What does the typedef keyword do?


      This keyword provides a short-hand way to write variable declarations. It is not a true data typing mechanism, rather, it is syntactic "sugar coating".
      For example


      typedef struct node
      {
        int value;
        struct node *next;
      }mynode;


      This can later be used to declare variables like this


      mynode *ptr1;
      & not by the lengthy expression
      struct node *ptr1;


      There are three main reasons for using typedefs:
          * It makes the writing of complicated declarations a lot easier. This helps in eliminating a lot of clutter in the code.
          * It helps in achieving portability in programs. That is, if we use typedefs for data types that are machine dependent, only the typedefs need to change when the program is ported to a new platform.
          * It helps in providing better documentation for a program. For example, a node of a doubly linked list is better understood as ptrToList than just a pointer to a complicated structure.
   Q What is the difference between constants defined through #define & the constant keyword?


      A constant is similar to a variable in the sense that it represents a memory location (or simply, a value). It is different from a normal variable, in that it cannot change it's value in the proram - it must stay for ever stay constant. In general, constants are a useful because they can prevent program bugs & logical errors(errors are explained later). Unintended modifications are prevented from occurring. The compiler will catch attempts to reassign new values to constants.
      Constants may be defined using the preprocessor directive #define. They may also be defined using the const keyword.
      So whats the difference between these two?


      #define ABC 5
      &
      const int abc = 5;


      There are two main advantages of the second one over the first technique. First, the type of the constant is defined. "pi" is float. This allows for some type checking by the compiler. Second, these constants are variables with a definite scope. The scope of a variable relates to parts of your program in which it is defined.
      There is also one good use of the important use of the const keyword. Suppose you want to make use of some structure data in some function. You will pass a pointer to that structure as argument to that function. But to make sure that your structure is readonly inside the function you can declare the structure argument as const in function prototype. This will prevent any accidental modification of the structure values inside the function.
   Q What are Trigraph characters?


      These are used when you keyboard does not support some special characters


          ??=    #
          ??(    [
          ??)    ]
          ??<    {
          ??>    }
          ??!    |
          ??/    \
          ??'    ^
          ??-    ~
   Q How are floating point numbers stored? Whats the IEEE format?


      IEEE Standard 754 floating point is the most common representation today for real numbers on computers, including Intel-based PC's, Macintoshes, & most Unix platforms.
      IEEE floating point numbers have three basic components: the sign, the exponent, & the mantissa. The mantissa is composed of the fraction & an implicit leading digit (explained below). The exponent base(2) is implicit & need not be stored.
      The following figure shows the layout for single (32-bit) & double (64-bit) precision floating-point values. The number of bits for each field are shown (bit ranges are in square brackets):


                       Sign   Exponent   Fraction   Bias
      --------------------------------------------------
      Single Precision 1 [31] 8 [30-23]  23 [22-00] 127
      Double Precision 1 [63] 11 [62-52] 52 [51-00] 1023


      The sign bit is as simple as it gets. 0 denotes a positive number; 1 denotes a negative number. Flipping the value of this bit flips the sign of the number.
      The exponent field needs to represent both positive & negative exponents. To do this, a bias is added to the actual exponent in order to get the stored exponent. For IEEE single-precision floats, this value is 127. Thus, an exponent of zero means that 127 is stored in the exponent field. A stored value of 200 indicates an exponent of (200-127), or 73. For reasons discussed later, exponents of -127 (all 0s) & +128 (all 1s) are reserved for special numbers. For double precision, the exponent field is 11 bits, & has a bias of 1023.
      The mantissa, also known as the significand, represents the precision bits of the number. It is composed of an implicit leading bit & the fraction bits. To find out the value of the implicit leading bit, consider that any number can be expressed in scientific notation in many different ways. For example, the number five can be represented as any of these:


              5.00 × 100
              0.05 × 10 ^ 2
              5000 × 10 ^ -3


      In order to maximize the quantity of representable numbers, floating-point numbers are typically stored in normalized form. This basically puts the radix point after the first non-zero digit. In normalized form, five is represented as 5.0 × 100. A nice little optimization is available to us in base two, since the only possible non-zero digit is 1. Thus, we can just assume a leading digit of 1, & don't need to represent it explicitly. As a result, the mantissa has effectively 24 bits of resolution, by way of 23 fraction bits.
      So, to sum up:


      1. The sign bit is 0 for positive, 1 for negative.
      2. The exponent's base is two.
      3. The exponent field contains 127 plus the true exponent for single-precision,  or 1023 plus the true exponent for double precision.
      4. The first bit of the mantissa is typically assumed to be 1.f, where f is the field of fraction bits. 



  Q. When should the register modifier be used?


      The register modifier hints to the compiler that the variable will be heavily used & should be kept in the CPU?s registers, if possible, so that it can be accessed faster. There are several restrictions on the use of the register modifier.
      First, the variable must be of a type that can be held in the CPU?s register. This usually means a single value of a size less than or equal to the size of an integer. Some machines have registers that can hold floating-point numbers as well. Second, because the variable might not be stored in memory, its address cannot be taken with the unary & operator. An attempt to do so is flagged as an error by the compiler. Some additional rules affect how useful the register modifier is. Because the number of registers is limited, & because some registers can hold only certain types of data (such as pointers or floating-point numbers), the number & types of register modifiers that will actually have any effect are dependent on what machine the program will run on. Any additional register modifiers are silently ignored by the compiler. Also, in some cases, it might actually be slower to keep a variable in a register because that register then becomes unavailable for other purposes or because the variable isn?t used enough to justify the overhead of loading & storing it. So when should the register modifier be used? The answer is never, with most modern compilers. Early C compilers did not keep any variables in registers unless directed to do so, & the register modifier was a valuable addition to the language. C compiler design has advanced to the point, however, where the compiler will usually make better decisions than the programmer about which variables should be stored in registers. In fact, many compilers actually ignore the register modifier, which is perfectly legal, because it is only a hint & not a directive.
 


Q. When should a type cast be used?


      There are two situations in which to use a type cast.
      The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly.
      The second case is to cast pointer types to & from void * in order to interface with functions that expect or return void pointers. For example, the following line type casts the return value of the call to malloc() to be a pointer to a foo structure.


      struct foo *p = (struct foo *) malloc(sizeof(struct foo));


      A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer to one type of structure or data type into another. In the
      rare events in which this action is beneficial, using a union to hold the values makes the programmer?s intentions clearer.



  Q. Can structures be assigned to variables & passed to & from functions?


      Yes, they can!
      But note that when structures are passed, returned or assigned, the copying is done only at one level (The data pointed to by any pointer fields is not copied!.


Q What is the difference between the declaration & the definition of a variable?.


      The definition is the one that actually allocates space, & provides an initialization value, if any.
      There can be many declarations, but there must be exactly one definition. A definition tells the compiler to set aside storage for the variable. A declaration makes the variable known to parts of the program that may wish to use it. A variable might be defined & declared in the same statement.


   Q Do Global variables start out as zero?



      Un initialized variables declared with the "static" keyword are initialized to zero. Such variables are implicitly initialized to the null pointer if they are pointers, & to 0.0F if they are floating point numbers.
      Local variables start out containing garbage, unless they are explicitly initialized.
      Memory obtained with malloc() & realloc() is likely to contain junk, & must be initialized. Memory obtained with calloc() is all-bits-0, but this is not necessarily useful for pointer or floating-point values (This is in contrast to Global pointers & Global floating point numbers, which start as zeroes of the right type).


 


Q To what does the term storage class refer? What are auto, static, extern, volatile, const classes?


      This is a part of a variable declaration that tells the compiler how to interpret the variable's symbol. It does not in itself allocate storage, but it usually tells the compiler how the variable should be stored. Storage class specifiers help you to specify the type of storage used for data objects. Only one storage class specifier is permitted in a declaration this makes sense, as there is only one way of storing things & if you omit the storage class specifier in a declaration, a default is chosen. The default depends on whether the declaration is made outside a function (external declarations) or inside a function (internal declarations). For external declarations the default storage class specifier will be extern & for internal declarations it will be auto. The only exception to this rule is the declaration of functions, whose default storage class specifier is always extern.
      Here are C's storage classes & what they signify:
          * auto - local variables.
          * static - variables are defined in a nonvolatile region of memory such that they retain their contents though out the program's execution.
          * register - asks the compiler to devote a processor register to this variable in order to speed the program's execution. The compiler may not comply & the variable looses it contents & identity when the function it which it is defined terminates.
          * extern - tells the compiler that the variable is defined in another module.


      In C, const & volatile are type qualifiers. The const & volatile type qualifiers are completely independent. A common misconception is to imagine that somehow const is the opposite of volatile & vice versa. This is wrong. The keywords const & volatile can be applied to any declaration, including those of structures, unions, enumerated types or typedef names. Applying them to a declaration is called qualifying the declaration?that's why const & volatile are called type qualifiers, rather than type specifiers.
          * const means that something is not modifiable, so a data object that is declared with const as a part of its type specification must not be assigned to in any way during the run of a program. The main intention of introducing const objects was to allow them to be put into read-only store, & to permit compilers to do extra consistency checking in a program. Unless you defeat the intent by doing naughty things with pointers, a compiler is able to check that const objects are not modified explicitly by the user. It is very likely that the definition of the object will contain an initializer (otherwise, since you can't assign to it, how would it ever get a value?), but this is not always the case. For example, if you were accessing a hardware port at a fixed memory address & promised only to read from it, then it would be declared to be const but not initialized.
          * volatile tells the compiler that other programs will be modifying this variable in addition to the program being compiled. For example, an I/O device might need write directly into a program or data space. Meanwhile, the program itself may never directly access the memory area in question. In such a case, we would not want the compiler to optimize-out this data area that never seems to be used by the program, yet must exist for the program to function correctly in a larger context. It tells the compiler that the object is subject to sudden change for reasons which cannot be predicted from a study of the program itself, & forces every reference to such an object to be a genuine reference.
          * const volatile - Both constant & volatile.


      The "volatile" modifier
      The volatile modifier is a directive to the compiler?s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the volatile modifier is desirable. The first case involves memory-mapped hardware (a device such as a graphics adaptor that appears to the computer?s hardware as if it were part of the computer?s memory), & the second involves shared memory (memory used by two or more programs running simultaneously). Most computers have a set of registers that can be accessed faster than the computer?s main memory. A good compiler will perform a kind of optimization called ?redundant load & store removal.? The compiler looks for places in the code where it can either remove an instruction to load data from memory because the value is already in a register, or remove an instruction to store data to memory because the value can stay in a register until it is changed again anyway.
      If a variable is a pointer to something other than normal memory, such as memory-mapped ports on a
      peripheral, redundant load & store optimizations might be detrimental. For instance, here?s a piece of code that might be used to time some operation:


      time_t time_addition(volatile const struct timer *t, int a)
      {
        int n;
        int x;
        time_t then;
        x = 0;
        then = t->value;
        for (n = 0; n < 1000; n++)
        {
          x = x + a;
        }
        return t->value - then;
      }


      In this code, the variable t->value is actually a hardware counter that is being incremented as time passes. The function adds the value of a to x 1000 times, & it returns the amount the timer was incremented by while the 1000 additions were being performed. Without the volatile modifier, a clever optimizer might assume that the value of t does not change during the execution of the function, because there is no statement that explicitly changes it. In that case, there?s no need to read it from memory a second time & subtract it, because the answer will always be 0. The compiler might therefore ?optimize? the function by making it always return 0. If a variable points to data in shared memory, you also don?t want the compiler to perform redundant load & store optimizations. Shared memory is normally used to enable two programs to communicate with each other by having one program store data in the shared portion of memory & the other program read the same portion of memory. If the compiler optimizes away a load or store of shared memory, communication between the two programs will be affected.



READ ANSWER and EXPLANATION

Sql Aptitude questions and answers


Here Are More Sql aptitude questions



as we were asked by several of our readers for Sql related questions for aptitude preparations & sql questions are asked a lot in placement papers so if u have any requests email us (kusumm14@yahoo.com)



Q. What is the use of the DROP option in the ALTER TABLE comm&?


It is used to drop constraints specified on the table.



Q. What is the value of ‘comm’ & ‘sal’ after executing the following query if the initial


value of ‘sal’ is 10000?


UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1;


sal = 11000, comm = 1000 .


Q. Why does the following comm& give a compilation error?


DROP TABLE &TABLE_NAME;


Variable names should start with an alphabet. Here the table name starts with an '&' symbol.



Q. What is the advantage of specifying WITH GRANT OPTION in the GRANT comm& in sql?


The privilege receiver can further grant the privileges he/she has obtained from the owner to any other user.



Q. What is the use of DESC in SQL?


Answer :


DESC has two purposes. It is used to describe a schema as well as to retrieve rows from table in descending order.


Explanation :


The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output sorted on ENAME in descending order.



Q. What is the use of CASCADE CONSTRAINTS?


When this clause is used with the DROP comm&, a parent table can be dropped even when a child table exists.



 


READ ANSWER and EXPLANATION

Top Sql Aptitude Questions for Aptitude

Some SQL Aptitude questions for Aptitude Preparations


Q  Which  is  the  subset  of  SQL  commands  used  to  manipulate  Oracle  Database
structures, including tables?
Data Definition Language (DDL)
Q  What operator performs pattern matching?
LIKE operator
Q  What operator tests column for the absence of data?
IS NULL operator
Q  Which command executes the contents of a specified file?
   START <filename> or @<filename>
Q  What is the parameter substitution symbol used with INSERT INTO command?
   &
Q  Which command displays the SQL command in the SQL buffer, and then executes
it?. 
   RUN


Q.  What are the wildcards used for pattern matching?
   _ for single character substitution
and % for multi-character substitution

Q  State true or false. EXISTS, SOME, ANY are operators in SQL.
   True
Q  State true or false. !=, <>, ^= all denote the same operation.
   True
Q. What are the privileges that can be granted on a table by a user to others?
  Insert, update, delete, select, references, index, execute, alter, all


READ ANSWER and EXPLANATION
 

© New Placement papers | Latest Placement Papers