1 / 31

Tejalal Choudhary SDBCT, Indore for queries send email to: tejalal.choudhary@gmail

Tejalal Choudhary SDBCT, Indore for queries send email to: tejalal.choudhary@gmail.com. What will be the output of the program?. #include< stdio.h > #include< conio.h > void main() { int i ; int sum=0; int n[]={2,2,2,2,2}; clrscr (); for( i =0;i<5;i++);

darcie
Download Presentation

Tejalal Choudhary SDBCT, Indore for queries send email to: tejalal.choudhary@gmail

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tejalal ChoudharySDBCT, Indorefor queries send email to: tejalal.choudhary@gmail.com

  2. What will be the output of the program? • #include<stdio.h> • #include<conio.h> • void main() • { • inti; • int sum=0; • int n[]={2,2,2,2,2}; • clrscr(); • for(i=0;i<5;i++); • sum=sum+n[i];//initial value of sum will be stored at n[5] • printf("Sum=%d",sum); • getch(); • } • 0 10 11 none

  3. What will be the output of the program? • #include<stdio.h> • #include<conio.h> • void main( ) • { • inti = 3, *j, **k ; • clrscr(); • j = &i ;//suppose address of i is 200 • k = &j ;//suppose address of j is 400 • printf ( "\n%u", j ) ; • printf ( ",%u", k ) ; • printf ( ",%d", * ( &i ) ) ; • printf ( ",%d", **k ) ; • getch(); • } • 200 400 202 400 • 200 3 400 3 • 400 3 200 3 • 200 400 3 3

  4. What will be the output of the program? • #include<stdio.h> • #include<conio.h> • void main( ) • { • inti = 3, *j, **k ; • clrscr(); • j = &i ; suppose address of i is 200 • k = &j ; //suppose address of j is 400 • printf ( "\n%u", j ) ; • printf ( ",%u", *k ) ; • printf ( ",%u", &j ) ; • printf ( ",%u", k ) ; • printf ( ",%d", *j ) ; • getch(); • } • 200 400 200 400 3 • 3 4 3 4 200 • 400 200 3 4 3 • 200,200,400,400,3

  5. What will be the output of the program? • #include<stdio.h> • #include<conio.h> • void hunk(int *, int *); • void main( ) • { • inti = 4, j = 6 ; • clrscr(); • hunk( &i, &j ) ; • printf ( "\n%d %d", i, j ) ; • getch(); • } • void hunk ( int *i, int *j ) • { • *i = *i * *i ; • *j = *j * *j ; • } • 4 6 • 6 4 • 16 36 • 8 16

  6. Which of the statements is incorrect • int num[6] = { 2, 4, 12, 5, 45, 5 } ; • int[] num={1,2,3,4}; • int n[ ] = { 2, 4, 12, 5, 45, 5 } ; • float press[ ] = { 12.3, 34.2 -23.4, -11.3 } ; • only third • only second • only fourth • none

  7. What will be the output of the program? • #include<stdio.h> • void main(){ • inti = 3, *x ; • float j = 1.5, *y ; • clrscr(); • x = &i ; • y = &j ; • //suppose address of i=200 and address of j=400 • x++ ; • y++ ; • printf( "\n %u ", x ) ; • printf( " %u", y ) ; • getch(); • } • 202 402 • 200 400 • 204 408 • 202 404

  8. What will be the output of the program? • #include<stdio.h> • void main(){ • intarr[ ] = { 10, 20, 30, 45, 67, 56, 74 } ; • int *i, *j ; • clrscr(); • //suppose base address of the array is 100 • i = &arr[1] ; • j = &arr[5] ; • printf ( "%d %d", j - i, *j - *i ) ; • getch(); • } • 2 16 • 4 26 • 2 64 • 4 36

  9. What will be the output of the program? • #include<stdio.h> • void main(){ • intarr[ ] = { 10, 20, 36, 72, 45, 36 } ; • int *j, *k ; • j = &arr [ 4 ] ; • k = ( arr + 4 ) ; • if ( j == k ) printf ( "The two pointers point to the same location" ) ; • else printf ( "The two pointers do not point to the same location" ) ; • getch(); • } • The two pointers point to the same location • The two pointers do not point to the same location • Compilation • errornone

  10. What will be the output of the program? • #include<stdio.h> • void main(){ • int num[ ] = { 24, 34, 12, 44, 56, 17 } ; • //suppose base adress of num is 200 • inti ; • clrscr(); • printf ( "\naddress = %u ", &num[0] ) ; • printf ( "element = %d %d ", num[0], *( num + 0 ) ) ; • printf ( "%d %d", *( 0 + num ), 0[num] ) ; • getch(); • } • address=200 element=34 34 34 34 • address=202 element=24 24 24 24 • address=200 element=12 12 12 12 • address=200 element=24 24 24 24

  11. Which of the statement are correct in C? • intarr[2][3] = { 12, 34, 23, 45, 56, 45 } ; • intarr[ ][3] = { 12, 34, 23, 45, 56, 45 } ; • intarr[2][ ] = { 12, 34, 23, 45, 56, 45 } ; • intarr[ ][ ] = { 12, 34, 23, 45, 56, 45 } ; • 1 and 2 • 1 and 3 • 3 and 4 • 2 and 4

  12. What will be the output of the program? • #include<stdio.h> • void main(){ • int s[4][2] = { { 1234, 56 }, { 1212, 33 }, { 1434, 80 }, { 1312, 78 } } ; • inti=0, j=1; • printf ( "%d ", *( *( s + i ) + j ) ) ; • } • 35 • 80 • 56 • 1234

  13. What will be the output of the program? • #include<stdio.h> • void change(int *, int); • void main(){ • int a[ ] = { 2, 4, 6, 8, 10 } ; • inti ; • change( a, 5 ) ; • for ( i = 0 ; i <= 4 ; i++ ) • printf( "\n%d", a[i] ) ; • getch(); • } • void change ( int *b, int n ) { • inti ; • for ( i = 0 ; i < n ; i++ ) • *( b + i ) = *( b + i ) + 5 ; • } • 2 4 6 8 10 • constant can not be added to pointer • 7 9 11 13 15 • wil print the address plus 5 for each element

  14. Which of the following is false about array in C • Compiler does perform bounds checking on an array. • The array variable acts as a pointer to the zeroth element of the array. In a 1-D array, zeroth element is a single value, whereas, in a 2-D array this element is a 1-D array. • On incrementing a pointer it points to the next location of its type. • If the array is initialized where it is declared, mentioning the dimension of the array is optional

  15. Are the expressions *ptr++ and ++*ptr same? • No • Yes • Can not say, it depends • Partially true

  16. What do the declarations stands for? • int ***j; • i is a pointer to a pointer to an int • i is a integer variable which can hold the address of pointer variable • none of the above • i is a pointer to a pointer to a pointer to an int

  17. Would the following program compile successfully? • void main() • { • char a[]=”Sunstroke”; • char *ptr=”Sunstroke”; • a=”Funstroke”; • ptr=”Funstroke”; • printf(“%s%s”,a,ptr); • } • No • Yes • Can not say • It depends

  18. What will be the output of the program? • #include<stdio.h> • #include<string.h> • void main(){ • char s[]="SDBCTINDORE"; • printf("%d",*(s+strlen(s))); • getch(); • } • 0 • 1 • 2 • 3

  19. What will be the output of the program? • #include<stdio.h> • #include<string.h> • void main(){ • char s[]="SDBCTINDORE"; • char p[]="SDBCTINDORE"; • if(s==p) • printf("Equal"); • else • printf("Not Equal"); • getch(); • } • Equal • Not Equal • Compilation error • none

  20. #include<stdio.h> • #include<string.h> • void disp(struct Book *); • struct Book{ • char aname[20]; • char bname[20]; • int price; • }; • void main(){ • struct Book b1= • {"SDBCT","SDBCE",1000}; • clrscr(); • disp(&b1); • getch(); • } • void disp(struct Book *b){ • printf("%s %s %d",b->aname,b->bname,b->price); • } • SDBCT SDBCE 1000 • Compile time error • Run time error • Syntax error

  21. Which of the following statements are true about file modes • In Read mode “r” Searches file. If the file is opened successfully fopen( ) loads it into memory and sets up a pointer which points to the first character in it. If the file cannot be opened fopen( ) returns NULL. • In write mode “w” Searches file. If the file exists, its contents are overwritten. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open file. • In append “a” mode Searches file. If the file is opened successfully fopen( ) loads it into memory and sets up a pointer that points to the last character in it. If the file doesn’t exist, a new file is created. Returns NULL, if unable to open file. • All of the above

  22. If a function is to be made to return more than one value at a time then return these values indirectly by using a call by reference. • false • true • can not return multiple values • not supported in C

  23. Which of the following operation can not be performed on pointer variables • Addition of two pointers • Multiplication of a pointer with a constant • Division of a pointer with a constant • All of the above

  24. Which of the following is false? • An array is similar to an ordinary variable except that it can store multiple elements of similar type. • C compiler performs bounds checking on an array. • The array variable acts as a pointer to the zeroth element of the array. In a 1-D array, zeroth element is a single value, whereas, in a 2-D array this element is a 1-D array. • Array elements are stored in contiguous memory locations and so they can be accessed using pointers. • 2 and 4 • 1 and 4 • only 2 • none of the above

  25. What is the difference between the 5’s in these two expressions? • int num[5] ; • num[5] = 11 ; • first is particular element, second is type • first is array size, second is particular element • first is particular element, second is array size • both specify array size

  26. When you pass an array as an argument to a function, what actually gets passed? • address of the array • values of the elements of the array • address of the first element of the array • number of elements of the array

  27. if int s[5] is a one-dimensional array of integers, which of the following refers to the third element in the array? • *( s + 2 ) • *( s + 3 ) • s + 3 • s + 2

  28. What will be the output of the program? • #include<stdio.h> • void main(){ • char arr[ ] = "Bamboozled" ; • int len1, len2 ; • len1 = strlen ( arr ) ; • len2 = strlen ( "Humpty Dumpty" ) ; • printf ( "\n%d ",len1 ) ; • printf ( " %d",len2 ) ; • getch(); • } • 11 12 • 9 11 • 10 12 • 10 13

  29. What will be the output of the program? • #include<stdio.h> • void main(){ • int *a[4]; • intm,i=20,j=30,k=23; • clrscr(); • a[0]=&i; • a[1]=&j; • a[2]=&k; • for(m=0;m<3;m++) • printf(" %d",*(a[m])); • getch(); • } • address of all variables • 20 30 23 • Compilation error • none

  30. What will be the output of the program? • #include<stdio.h> • #include<string.h> • void main(){ • FILE *fp ; • char ch ; • fp = fopen ( "Q1.C", "r" ) ; • while ( 1 ) • { • ch = fgetc ( fp ) ; • if ( ch == EOF ) • break ; • printf ( "%c", ch ) ; • } • fclose ( fp ) ; • getch (); • } • Will display the contents of the “Q1.c” file • Run Time Error • Compile time error • File does not found error

  31. What will be the output of the program? • #include<stdio.h> • #include<string.h> • void disp(int *); • void main(){ • inti ; • int marks[ ] = { 55, 65, 75, 56, 78, 78, 90 } ; • for ( i = 0 ; i <= 6 ; i++ ) • disp ( &marks[i] ) ; • getch(); • } • void disp ( int *n ) • { • printf ( "%d ", *n ) ; • } • 55 65 75 56 78 78 90 • 90 78 78 56 75 65 55 • It will print the address of all elements • Compile time error

More Related