Global Edge c Program

17
Paper: Global Edge Placement Paper (Technical- C & Data Structure) C Paper 1. What is the output of the following code ? int main( ) {for( ; ;); printf("Hello\n"); return 0; } Runs in an infinite loop without printing anything. 2. Output of the code? FUNC (int *p) {p = (int *)malloc(100); printf("p:%x",p); } int main( ) { int *ptr; FUNC(ptr); printf("Ptr:%x",ptr); return 0; } Both print different values. 3. Output of the code? int main() { char a[] = "world"; printf("%d %d\n",strlen(a),sizeof(a)); return 0; }

description

• I request Electronics and communication ENGINEERING students to visit my blog for more……• abhishek1ek.blogspot.com• awhengineering.blogspot.com

Transcript of Global Edge c Program

Page 1: Global Edge c Program

Paper: Global Edge Placement Paper (Technical- C & Data Structure)C Paper

1. What is the output of the following code ?int main( ){for( ; ;);printf("Hello\n");return 0;} Runs in an infinite loop without printing anything.

2. Output of the code?FUNC (int *p){p = (int *)malloc(100);printf("p:%x",p);}int main( ){int *ptr;FUNC(ptr);printf("Ptr:%x",ptr);return 0;} Both print different values. 3. Output of the code?int main(){char a[] = "world";printf("%d %d\n",strlen(a),sizeof(a));return 0;} ans:5,64. What is the output generated?main(){char *s = "Hello";printf("%s",1(s));} ans:ello

Page 2: Global Edge c Program

5. Interpret the given declarationchar ( * ( f ( ) ) [ ] )( )

Ans:f is a function returning pointer to array[] of pointer to function returning char.

Data Structure:

1. A binary tree of height h, h > 0 has ans: at least h and atmost (2^h) - 1 elements in it.2. Thrashing is ans: increase in page faults leading to decrease in CPU utilization.3. Recursive Descent parser is a type of Ans: Top Down parser.4. alloca() allocates memory from ans: Stack.5. What is the octal equivalent of decimal (5468).ans None of these.

PAPER: Global Edge Placement Paper2 (Technical-C & Fundamentals)

1.Where is the MBR stored?1. maintained by OS2. MBR is in Boot.3 MBR is in First sector of HDD4. None of the above.

2. Where is the partition table stored?1. BIOS2. CMOS Setup3. MBR4. stored per partition.

3. Where is the boot record stored?1. BIOS2. CMOS Setup3. MBR4. stored per partition.

4. How many primary partitions can be created?Ans : 4.

5. What is the difference between primary & extended partition?ans: primary cannot be subdivided but extended can be.

6. Can we create 2 primary dos partitions?Ans: Yes

7. Can we create 2 extended partitions ?Ans: No.

Page 3: Global Edge c Program

8. How many partitions can be created on a given hard disk?a) Depends on the size of Disk. b) 24 c)4 d)26

9. Can we hide a partition?Ans: Yes.

10. Sliding window protocol lies in which layer?Ans : 3. Data link layer

11. Which is the highest priority interrupt .1. rst5.52. rst6.53. TRAP4. HLD

12. 8085 isAns : 8 bit

13. protected mode is present in which Processor1. 8085 2. 8086 3. 80386 4.8087

14. The no. of address lines required to address 4k of memoryAns: 12

15) Where is CMOS setup storedAns : CMOS Ram

16) main(){int a;char *p;a = sizeof(int) * p;printf("%d\n",a);}ans:compile error

17)#define SIZE sizeof(int)main(){ int i=-1;if( i < SIZE )printf("True\n");elseprintf("False\n");}ans: False

18) int (*fun())[] ans: function returning a pointer to an array

Page 4: Global Edge c Program

19) main(){int a=8,d;int *p;p=&a;d=a/*p;print("%d\n",d);} ans) compiler error20)main(){char *a="Hello";*a++ = 'h';printf("%s\n",a);} ans :ello21) main(){char p[]="Hello";p[0]='h';printf("%s\n", p);} ans) hello22)#define mysizeof(a) (&a+1) - &amain(float d;printf("%d\n", mysizeof(d) );}note: assume sizeof float is 8 bytes

ans) 123) main(){ int *p=10;printf("%d\n",*p);} ans) run time error24) main(){int i=-1;i<<=2;printf("%d\n",i);} ans) -426) main(){int i= 0xffffffff;printf("%d\n",i);}note: size of int is 4 bytes ans) -1

Page 5: Global Edge c Program

Paper: Global Edge Placement Paper (Technical- C Section)

C Paper1. main(){ int i;i=(2,3);printf("%d",i);} ans : 32. main(){char str[]="GESL";printf("%d %d",sizeof(str),strlen(str));} ans: 5, 43. main(){ for(i=0;i++;i<100) printf("hello world\n"); }ans: 0 times.

4. main(){ for(i=1;i++;i<100) printf("hello world\n"); }ans: infinite loop

5. main(){ char c; scanf("%s",c); }ans: Compiler dependent.

6. main(){int k=5;for(++k<5 && k++/5 || ++k<8);printf("%d\n",k);}ans: 7

7. main(){int *ptr1,*ptr2;ptr1=(int *)malloc(sizeof(int));ptr2=func(20,10,ptr1);printf("%d %d\n",*ptr1,*ptr2);} int *func(int a, int b, int *c) { int x=a+b; *c=a-b; return(&x); }Ans: Bug in the code.

8). int main() {int i = 10, j ;if ( ( j = ~i ) < i )printf ( "True" ) ;elseprintf ( "False" ) ;}ans : True

9. How many bytes are required to create a 3*3 matrix using double pointerans: 12

Page 6: Global Edge c Program

10. take int=4,float=8,char=1main() {FILE *fp;printf("%d\n",sizeof(fp) );} Ans:411. main(){int a=10,20;a^=b^=a^=b;printf("%d\n %d\n",a,b); Ans : a=20 b=10

12. main() {int i=10;switch(i) {case 10: printf("Hello "); {case 1 : printf("World ");}case 5: printf("Hello World ");}} Ans : Hello World Hello World

13. main() {char str1[]="Hello";char str2[]="Hello";if ( str1==str2 )printf("True\n");elseprintf("False\n");} Ans: False.

14. main(){# include <stdio.h>int i = 10 ;printf("%d\n", i/2 );} ans : 515. #include <stdio.h># pragma pack(2)struct SIZE {int i;char ch ;double db ;} ;main () {printf ( "%d\n",sizeof(struct SIZE) );} a)12 b)14 c)16 d)8

Page 7: Global Edge c Program

GLOBAL EDGE Placement Question Papermain(){ int arr[]={ 1,2,3,4 };int *ptr ;;;;ptr++ = arr;printf("%d,%d",ptr[2],arr[2]);return 0;} ans : lvalue required for ptr;

2>main(){char s[10];scanf ("%s",s);printf(s);} ans : prints abcd.

3>main(){char c = 255;printf ("%d",c);return 0;} ans b: prints -1.4>main(){int i;for (i=7;i<=0;i--)printf ("hello\n");} ans : prints nothing.5>main(){printf( printf ("world") );}  ans : compiler error.

computer concepts1> A c source code file can be ans c : both compiled and interpreted2> c prigramming approach is ans :top down approach3> The access time is less for ans :registers

Page 8: Global Edge c Program

4>resolving of external variables in a program is done at ans : link time.5> interrupts inform process about ans : events external to process asynchronously

/* C question and answersAll questions are tested in Turbo C compalier and have not beentested in gcc or ( linux platform) */

1)#includemain(){scanf("%d");printf();}which of the following is correct? ans)compilation error2)#include#define islower(c) ('a'<=(c) && (c)<='z')#define toupper(c) (islower(c)?(c)-('a'-'A')c))main(){char *p="i am fine";while(*p)printf("%c",toupper(*p++));} ans : AFE( macro substitution 3 times)3)#includemain(){200;printf("tricky problem");}ans)warning message

4)which is the null statement? a) ; b) {} c) '\0'; d)all of theseans : a

5)what is the correct prototype of printf function ?ans)printf(const char *p,...);

/* questions on computer concepts */1)which of the following is not a system file?a).sys b).com c).ini d)none ans : d

2)A magnetic tape is equivalent to which of the following structure?

Page 9: Global Edge c Program

a)Graphs b)trees c)Lists d)Dictionaries ans : c3)For a linked list implementation which searching technique is notapplicable?a)linear search b)none c)quick sort d)binary search ans : d

4)Encryption and decryption is done in which layer?a)DLL b)Network layer c)transport layer d) Presentation layer ans : d

5)which of the following is not performed by the OS?a)cpu scheduling b)memory management c)Transaction d)none ans : c

Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?

A. rem = 3.14 % 2.1;

B. rem = modf(3.14, 2.1);

C. rem = fmod(3.14, 2.1);

D. Remainder cannot be obtain in floating point division.

Answer & Explanation

Answer: Option CExplanation:fmod(x,y) - Calculates x modulo y, the remainder of x/y. This function is the same as the modulus operator. But fmod() performs floating point divisions.

Example:

#include <stdio.h>#include <math.h>

int main (){ printf ("fmod of 3.14/2.1 is %lf\n", fmod (3.14,2.1) ); return 0;}

Output:fmod of 3.14/2.1 is 1.040000View Answer Online Compiler Report Discuss in Forum

2.  What are the types of linkages?

A. Internal and External B. External, Internal and None

C. External and None D. Internal

Answer & Explanation

Answer: Option BExplanation:External Linkage-> means global, non-static variables and functions.Internal Linkage-> means static variables and functions with file scope.None Linkage-> means Local variables.View Answer Online Compiler Report Discuss in Forum

Page 10: Global Edge c Program

3.  Which of the following special symbol allowed in a variable name?

A. * (asterisk) B. | (pipeline)

C. - (hyphen) D. _ (underscore)

Answer & Explanation

Answer: Option DExplanation:Variable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit.Examples of valid (but not very descriptive) C variable names:=> foo => Bar => BAZ => foo_bar => _foo42 => _ => QuUx View Answer Online Compiler Report Discuss in Forum

4.  Is there any difference between following declarations?1 : extern int fun();

2 : int fun();

A. Both are identical

B. No difference, except extern int fun(); is probably in another file

C. int fun(); is overrided with extern int fun();

D. None of these

Answer & Explanation

Answer: Option BExplanation:extern int fun(); declaration in C is to indicate the existence of a global function and it is

defined externally to the current module or in another file.int fun(); declaration in C is to indicate the existence of a function inside the current

module or in the same file.View Answer Online Compiler Report Discuss in Forum

5.  How would you round off a value from 1.66 to 2.0?

A. ceil(1.66) B. floor(1.66)

C. roundup(1.66) D. roundto(1.66)

Answer & Explanation

Answer: Option AExplanation:

/* Example for ceil() and floor() functions: */

#include<stdio.h>

Page 11: Global Edge c Program

#include<math.h>

int main(){ printf("\n Result : %f" , ceil(1.44) ); printf("\n Result : %f" , ceil(1.66) ); printf("\n Result : %f" , floor(1.44) ); printf("\n Result : %f" , floor(1.66) );

return 0;}// Output:// Result : 2.000000// Result : 2.000000// Result : 1.000000// Result : 1.000000

6.  By default a real number is treated as a

A. float B. double

C. long double D. far double

Answer & Explanation

Answer: Option BExplanation:In computing, 'real number' often refers to non-complex floating-point numbers. It include both rational numbers, such as 42 and 3/4, and irrational numbers such as pi = 3.14159265...When the accuracy of the floating point number is insufficient, we can use thedouble to define the number. The double is same as float but with longer precision and takes double space (8 bytes) than float.To extend the precision further we can use long double which occupies 10 bytes of memory

space.View Answer Online Compiler Report Discuss in Forum

7.  Which of the following is not user defined data type?1 :

struct book{ char name[10]; float price; int pages;};

2 :long int l = 2.35;

3 :enum day {Sun, Mon, Tue, Wed};

A. 1 B. 2

C. 3 D. Both 1 and 2

Answer & Explanation

Page 12: Global Edge c Program

Answer: Option BExplanation:C data types classification are

1. Primary data types1. int2. char3. float4. double5. void

2. Secondary data types (or) User-defined data type1. Array2. Pointer3. Structure4. Union5. Enum

So, clearly long int l = 2.35; is not User-defined data type. (i.e.long int l = 2.35; is the answer.)View Answer Online Compiler Report Discuss in Forum

8.  Is the following statement a declaration or definition?extern int i;

A. Declaration B. Definition

C. Function D. Error

Answer & Explanation

Answer: Option AExplanation:Declaring is the way a programmer tells the compiler to expect a particular type, be it a variable, class/struct/union type, a function type (prototype) or a particular object instance. (ie. extern int i)

Declaration never reserves any space for the variable or instance in the program's memory; it simply a "hint" to the compiler that a use of the variable or instance is expected in the program. This hinting is technically called "forward reference".View Answer Online Compiler Report Discuss in Forum

9.  Identify which of the following are declarations1 : extern int x;

2 : float square ( float x ) { ... }

3 : double pow(double, double);

A. 1 B. 2

C. 1 and 3 D. 3

Answer & Explanation

Answer: Option CExplanation:extern int x; - is an external variable declaration.

double pow(double, double); - is a function prototype declaration.

Therefore, 1 and 3 are declarations. 2 is definition.View Answer Online Compiler Report Discuss in Forum

Page 13: Global Edge c Program

10.  In the following program where is the variable a getting defined and where it is getting

declared?

#include<stdio.h>int main(){ extern int a; printf("%d\n", a); return 0;}int a=20;

A. extern int a is declaration, int a = 20 is the definition

B. int a = 20 is declaration, extern int a is the definition

C. int a = 20 is definition, a is not defined

D. a is declared, a is not defined

Answer & Explanation

Answer: Option AExplanation:- During declaration we tell the datatype of the Variable.- During definition the value is initialized.

11.  When we mention the prototype of a function?

[A]. Defining [B].Declaring

[C]. Prototyping [D]. Calling

Answer: Option B

Explanation:

A function prototype in C or C++ is a declaration of a function that omits the function body but does specify the function's name, argument types and return type.

While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface.

Page 14: Global Edge c Program

• I request Electronics and communication ENGINEERING students to visit my blog for more……

• abhishek1ek.blogspot.com

• awhengineering.blogspot.com