UNIT-1 Important for MID-1

 

Explain about Formatted Input in detail with  the prototype of ‘scanf’’ function in C programming

scanf() function

v  The scanf() function id formatted input function it depends on Format specifiers. 

v  The scanf() function is used to read multiple data values of different data types from the keyboard.

v  The scanf() function is built-in function defined in a header file called "stdio.h". When we want to use scanf() function in our program, we need to include the respective header file (stdio.h) using #include statement.

Syntax:

scanf("format strings",&variableNames);


Format string: %d, %c, %f, %s has been use as format string.

Variable list: Name of variable followed by address operator where input though keyboard been transferred.
Example

scanf(%d”,&a);---------->Integer input

scanf(“%c”,&a);---------> character input

scanf(“%f”,&a);---------> float input

scanf(“%s”,&a);---------> string input

Space will not be accept through keyboard

Scanf("%d%d%s",  &a, &b, &c);

Example Program

#include<stdio.h>

int main()

{

                int i;

                printf("\nEnter any integer value: ");

                scanf("%d",&i);

                printf("\nYou have entered %d number",i);  

                return 0;

}

Output:



 

1.      Constants and types of constants with examples

 

Definition:

A constant is a named memory location which holds only one value throughout the program execution.

Types of Constants:

1.      Integer constants

2.      Floating Point constants

3.      Character Constants

4.      String Constants

Integer constants

v  An integer constant can be a decimal integer or octal integer or hexadecimal integer.

v  A decimal integer value is specified as direct integer value whereas octal integer value is prefixed with 'o' and hexadecimal value is prefixed with 'OX'.



Floating Point constants

v  A floating-point constant must contain both integer and decimal parts.

v  Some times it may also contain the exponent part. When a floating-point constant is represented in exponent form, the value must be suffixed with 'e' or 'E'.

Example

Float f=3.14

The floating-point value 3.14 is represented as 3E-14 in exponent form.

Character Constants

A character constant is a symbol enclosed in single quotation. A character constant has a maximum length of one character.

Example

char ch='A';

char b='2';

char c='m';

String Constants

A string constant is a collection of characters, digits, special symbols and escape sequences that are enclosed in double quotations.

Example:

Char name [30] =”Hi How r u?”

 

 

 

Explain the precedence and associativity rules of operators help in executing a ‘C’ expression with an example.

C Operator Precedence and Associativity

 Operator Precedence:

Operator precedence is used to determine the order of operators evaluated in an expression. In c programming language every operator has precedence (priority). When there is more than one operator in an expression the operator with higher precedence is evaluated first and the operator with the least precedence is evaluated last.

Example:

10 + 4 * 3 / 2

In the above expression, there are three operators +, * and /. Among these three operators, both multiplication and division have the same higher precedence and addition has lower precedence. So, according to the operator precedence both multiplication and division are evaluated first and then the addition is evaluated. As multiplication and division have the same precedence they are evaluated based on the associativity. Here, the associativity of multiplication and division is left to right. So, multiplication is performed first, then division and finally addition. So, the above expression is evaluated in the order of * / and +. It is evaluated as follows...

4 * 3 ====> 12
12 / 2 ===> 6
10 + 6 ===> 16
the expression is evaluated to 
16.

 

 Operator Associativity:

Operator associativity is used to determine the order of operators with equal precedence evaluated in an expression. In the c programming language, when an expression contains multiple operators with equal precedence, we use associativity to determine the order of evaluation of those operators.

Let us try to evaluate an arithmetic expression as shown below:

 

x = a-b/3+c*2-1

 

Let a = 9, b =12, and c=3. Then our expression becomes:

 

x = 9-12/3+3*2-1

 

From the above table, we can see that the * and / operators are having higher precedence than + and – operators. Also, the * and / operators are at the same level of precedence, so we have to apply the associativity rules. Since the associativity rule is left-to-right, we apply the / operator first and the expression evaluates to:

 

x = 9-4+3*2-1

 

Next, we apply the * operator and the expression becomes:

 

x = 9-4+6-1

 

Next, we apply the first – operator as the – and + operators are at the same level and the associativity rule is from left to right. The expression becomes:

 

x = 5+6-1

 

Now, we apply the + operator and the expression become:

 

x = 11-1

 

Finally, we apply the – operator and the result is:

 

x = 10



 

 

netaji gandi Monday, December 12, 2022
Loop : C Language

 

Loop : C Language

 




 

Loop

 

Suppose you’re a class teacher and your college organized a tour for somewhere so you have assigned a task to fill up tour fee form. Total 200 hundred students in your class, in this situation you need to reach each student seat and collect fees. If we analysis from computer point of view for this scenario then you need to take total 200 step for achieve this.

 

This was real life an example which creates a basic idea of repetitive task. This type of task needs some automatic process which minimizes our effort then loop is your solution. Following are some example of task where you need loop.

 

·                     Printing all numbers between 1 to 100

·                     Printing your name a number of times

·                     Accessing some continuous item like arrays


C language gives you three types of loops to accomplished repetitive task.

·                     While

·                     For

·                     Do-while

While Loop

Syntax:

 

As you can see in while loop syntax a condition is being check at entry point of loop if condition is true then control goes to loop body and after running last statement control return top to loop and again check condition this process continue until condition goes false.

 

While loop is easy to understand and use. You should be master of while loop before jump to other loop s because it make your looping basic knowledge more strong.

 

void main()

{

     int number=1;     

     while(number<=10)

     {

         printf("\n\t%d",number);

         number+=1;

     }     

}

 

 

For Loop


Next category of looping is for loop which is more powerful than other category of loops because it decreases number of lines from your program. This is little bit complicated for beginner but ones you understand it then it implement complicated logic in few line of code.

Syntax:



 

Rules of for loop

·                     First step is to initialize variable

·                     Second step check condition

·                     After check condition if it is true then control goes to loop body otherwise outside and stop loop

·                     After running all statement of loop control goes to increment and decrement section through step 4 then move to condition check

·                     Step 2, 3 and 4 run till condition remain true.

For Loop Flow Chart


 

 

void main()

{

     int number;

     for(number=1;number<=10;number++)

     {

         printf("\n\t%d",number);

     }

}

 

 

Do-while Loop


An exit control loops because condition is being check on bottom side of loop So this will run at least one time when condition is false.

 Syntax :

 



void main()

 

{

     int number=1;

     do

     {

         printf("\n\t%d",number);

         number++;

     }while(number<=10);

}

 


 


netaji gandi
JNTUK MID-1 Online Bites and Important Notes A.Y 2022-23 PROGRAMMING FOR PROBLEM SOLVING USING C

 

PROGRAMMING FOR PROBLEM SOLVING USING C (R20)


NOTE: “” Mark is the respective answer.

 

1. Size of a union is determined by sizeof,

           A. first member of union                    B. last member of union 

          C. sum of sizes of all members            D. biggest member of union


2. Output of the following program: float i-2.0; float j-1.0; float sum=0.0; main() { while(i/j>0.001) {          j+=j; sum-sum+(i/j); printf("%f/n, sum); } }

                    A. 8                  B. 10                C. 9                  D. 11


3.  Which loop is most suitable to first perform the operation & then test the condition? 

                 A. for loop              B. while loop       C. do while loop         D. repeat loop


4.  Output of the following program: int i, main() (if(1), else printf(else), return 0,)

      A run time error        B. else block executed     C. if block executed     D. compile time error


5. Which of the following sets first n characters of a string to a given character?

              A strnit( )    B. strset( )            C. strcset( )      D. strnset( )

6. Consider the following two C lines: 1: int var1; 2: extern int var2; Which of the following statements         is correct?

         A.   1 defines & declares var1,but second statement only declares var2

         B.    both statements declare define variables var1&var2

         C.    both statements only declare variables and dont define them

         D.   2 defines & declares var2,but 1 only declares var 1


7.       scanf() is a_____ function

            A. one to one        B. many to many                      C. many to one            D. one to many

8. Which loop is correct?

        A. do{//code) while( condition):                       B. do[//code) while condition)!

        C. do{ //code}while(condition);                   D. do(code);


9. Output of the following program: main() { printf(x,-1>>1); return 0; }

        A. 0fff              B. fff0              C. f0ff              D. ffff

10. Output of the following program: union test (int x, char arr[4]; int y, ); int main()

(union test t; t.x=0; t.arr[1]-G; printf("%s,t.arr); ) Assume, size of (char)=1 sizeof(int) 4

        A. error                        B. garbage value         C. G               D. nothing printed


11. Output of the following program typedef struct (int A; char B; char C, )info, main(){ printf("%d,sizeof(info)); }

        A. 8✓               B. 10                C. 14                D. 12

12. String is a

        A series of only numbers                    B. one character

        C. series of only one character           D. series of characters

13. Output of the following program: #include<stdio.h> int main() { register int i=10; int

*ptr-&i; printf("%d, *ptr); return 0; }


        A may generate compiler error✓                  B. may generate runtime error

        C. prints 0 on all compilers                                 D. prints 10 on all compilers


14. Output of the following program: #include<stdio.h> int main() { int i-3; printf("%d, (++1) ++); return 0; }

            A. 5                  B. 4                  C. 3                  D. compile time error


15. Output of the following program: main() { int a[5]; printf(%u,&a+1); }


        A. 2004            B. 2020✓                     C. 2040                        D. 2022


16. Structure of a C program can be mainly generalized into ______ parts


        A. 5               B. 6                  C. 4                  D. 3



1. Output of the following program: main() { Unsigned int a=0xffff, 'a; printf(%x‚a); }


            A. 0000✓                     B. 00ff             C. ffff               D. ddfd


2. int main() { int i=1024; for(;i;i>>=1) printf(hi); } How many times hi is printed?

        A. 11             B. 0                  C. infinite                    D. 10


3. Output of the following program: int i; main() { if(1); else printf(else); return 0; }

        A.  else block executed

        B.  compile time error

        C.  if block executed 

        D. run time error

4. Output of the following program: union test { int x; char arr[4]; int y; ); int main() (union test t; t.x=0; t.arr[1]-G; printf("%s,t.arr);} Assume, size of (char)=1 sizeof(int) 4


            A. G               B. nothing printed                   C. error                       D. garbage value


5. Return type of getchar() is

        A char              B. int✓                         C. float            D. unsigned char


6. In an enumerated type, each integer value is given an identifier called

            A. varying constant                             B. enumeration constant

            C. integer Constant                             D. constant


7. User defined data type can be derived by______

            A. int                 B. float                           C. typedef                 D. char


8. Output of the following program: main() { int a[5]; printf("%u,&a+1); }


        A. 2020                     B. 2040                        C. 2022                        D. 2004

9. Output of the following program: float i=2.0; float j-1.0; float sum=0.0; main() { while

(i/j>0.001) (j+=j; sum=sum+(ij); printf("%f\n,sum); } }


            A. 8                  B. 11✓             C. 9                  D. 10


10. Output of the following program: main(){ printf(%c,5[Geeks Quiz]); }


A. runtime error                      B. compile time error             C. Q               D. S


11. ____ is used to store integers.


A. Twos Complement Method                    B. Sign and Magnitude Method

C. Threes Complement Method                     D. Ones Complement Method


12. Output of the following program: main() { int a-1;b-0; b-a+++ a++; printf(%d%d,a,b); }


A. 36                B. compiler dependent                       C. 33             D. 34

13. C was derived from which of the following languages:

            A. MODULA-2              B. PASCAL           C. MODULA-3              D. B, BCPL


1. Output of the following program #include<stdio.h> int main() ( register i int *ptr-&i, printf("%d, *ptr); return 0,)


        A. may generate compiler error✓                 B. prints 0 on all compilers

        C. prints 10 on all compilers                           D. may generate runtime error


2 What is order of execution iteration becomes false given for loop? for(1,2,3) (4) if 2 after one

        A 2,1,4,3,2                   B. 3,4,1,2,2                  C. 1,4,3,2,2                  D. 1,2,4,3,2


3. Output of the following program: main() (Unsigned int a-Oxffff, 'a, printf(x,a);


        A. 00ff              B. 0000                    C. ddfd             D. ffff


4. Output of the following program: main() { int i-0, if(-0) { printf(hello).continue, ))


        A hello is printed infinite times                      B. compile time error

        C. hello                                                            D. varies


5 .Output of the following program main() (int i-0, switch() (case 0: case 0 printf(hi), ))


        A. run time error                     B.haihi             C. compile error      D.hi


6. Output of the following program typedef struct (int A; char B, char C, )info, main( printf("%d,sizeof(info)), )


        A 10                 B.8                 C 12                D. 14


7. Output of the following program #include<stdio.h> int main() (int a-10,b-20,c-30, if(c>b>a) printf(true), else printf(false), return 0;)

        A 1/0    B. Compiler error                   C. True                        D. False 


8. Output of the following program: main() (int a[5], printf("%u,&a+1), )


        A 2022             B. 2004                        C 2040             D. 2020


9. Output of the following program: main()( printf("%c.5[Geeks Quez]).)


A compile time error              B. S                  C runtime error          D. Q

10 Output of the following program main()( char *s-Geeks Quiz, int n-7,printf("%. *s,n.), ) 

    A. nothing printed B. Geeks Q    C. Geeks Qu D. Geeks Quiz

11. Output of the following program: float i-2.0; float j-1.0, float sum-0.0, main while(/j>0.001) (j+j, sum-sum+(1); printf("%fin, sum).)) 


        A. 9.        B. 10    C. 8       D. 11


12. S1 Promotion occurs if the right expression has lower rank. S2 Demotion occurs if right expression has higher rank

A. S2 is true &S1 is false         B. only $1        C. both S1&S2 are true ✓     D. SI is true & $2 is false


13. Which of following operator connects structure none to its member none?.

            A . -                   B.*      C. +      D. .


14. Output of the following program: union test (int x, char arr[4], int y.), int main( (union test 1; 1 x-0, tarr[1]-G, printf("%s,tarr);) Assume, size of (char)-1 sizeof(int)-4 


        A. G     B garbage value            C. nothing printed            D. error


15 Output of following #include<stdio.h> int var-20, int main() (int var var, printf("%d,var); return 0,)

        A 0       B 20     C. Compile error      D. Garbage value


16. How many times will the following for loop run? for(int -1;i<10;i++)()


        A. 11        B.8            C. 9         D. 10

 

1. Output of the following program include<stdio.h> Int main() (typedef static int *, int j, ia&j, printf(“%d, “a); return 0,)


        A.D      B garbage value          C. runtime error         D. compile error


2_bool datatype is defined in______ header file

        A stdio.h           B. stdbool .h             C. stdin .h                    D. stdtrue/stdfalse h


3. int main(int 1=1024; for(>>=1) printi(ha), ) How many times hi is printed?

        A infinite          B. 10    C. 11✓             D. 0


4 languages uses symbols, or mnemonics, to represent the various machine language instructions


    A High-level     B. Machine      C. Compilation            D. Assembly


5. Output of the following program: main() (unsigned int i-65000, while(i++1=0); print%d.), return 0;)

       

     A. 1✓               B. run time error                     C. 0      D. infinite loop


6. Twos complement of a number x is

     A x        B. x-1         C. x+1                       D. x+0.1


7 Output of the following program typedef struct (int A, char B, char C. )info, main(){ printf(d,sizeof(info));)


    A. 12                B. 8               C. 14                D. 10


8. Output of the following program: #include<stdio.h> int main() (int i=3, print%d(++)++), return 0,)

    A 3                   B. 4                  C. 5✓               D. compile time error

9 Output of the following program: main() (int c[5], a++//assume address of a is 2000,sizeof integer is        32 bit printf(“%u,a); )

        A 2004             B 2002             C. Lvalue required✓               D. 2020


10. Output of following #include<stdio.h> int var-20, int main() (int var var. printf(“%d,var), return 0,)

        

            A .0                  B. Compile error                     C. Garbage value                 D. 20


11. Explicit type conversion uses a______operator

        A typechecking                         B. typecast                 C.sizeof            D. typeof


1. Output of the following program main()( typedef struct tag( char s[10], int a ) har, har

h1,h2-(IHelp, 10), hl-h2, hl. Str[1]-h; printf(“%s %d,hl str.hl.a).)

                A ERROR

                B. Ihelp, 10

                C.IHelp.0 

                D. IHelp,10

2. An array is a

        A collection of values of same datatype

        B.   collection of values of different datatype

        C.   collection of same values

        D.  collection/not a collection

3. Output of the following program #include<stdio.h> int main() ( register int -10, int “ptri, printf(“%d,”ptr); return 0,)  

        A. prints 10 on all compilers

        B. prints 0 on all compilers 

        C. may generate compiler error

        D. may generate runtime error


4. Output of the following program: main() (int i-0, if(-0) (printf(hello). Continue, )) 

            A hello 

            B.   varies

            C.   hello is printed infinite times

            D.  compile time error

5.  Output of the following program main (int loop-10,while(printf(hello)&&loop-);)

        A hello hello (infinite times)

        B. hello hello (10 times) 

        C hello hello. (11 times)

        D. hello

6. Output of the following program typedef struct (int A, char B, char C. )info, main(){ printf(“%d,sizeof(info)), )

A 10

B. 8

C. 14

 D. 12

7. What loop requires only braces?

A repeat

B.   for

C.   do

D.  while

8. sprintf( ) is a____ function

A many to one

B.   many to many

C.   one to one

D.  one to many

9. Bitwise can be used to reverse a sign of number.

A. Yes 

B. No

C Need extra information.

 D. Maybe 

10. Output of the following program main() (int a-1,6-0, ba+++++; printf%d%d,a,b), )

A.   compiler dependent

B.   33.

C.   34

D.  36

 

11. Which of the following is correct with respect to jump statements in c?

A.   break

B.   return

C.   continue 

D.  all


12. Which of the following for down given scanf() is true? Scanf(%4s,str),


A.   reads minimum 4 characters

B.   reads exactly 4 characters

C.   reads nothing

D.  reads multiples of 4 characters

13. Getting the program into memory is the function of an operating system program known as the

A.   Linker

B.   Loader

C.   Compiler

D.  Text-editor

1. Loops are required for

A simplicity 

B.   no use

C.   repetition of blocks any no of times

D.  cant say


2. Function to rename a string?

A.   strrev

B.   strstr

C.   revstr

D.  strreverse()

3. Output of the following program union test (int x, char arr[4], int y.), int main()(union

test t, 1-0, tarr[1]-G, printf(“%star), ) Assume, size of (char)-1 sizeof(int)==4

        

A error

B.G

C.   garbage value

D.  nothing printed


4. Output of the following program main( printf(“%c.5[Geeks Quiz]), )

A. runtime error 

B  .compile time error

C  .Q

D. S


8. The_____ operator can be used to turn masked bit off


A. &

B.^

C.’

D. I

9. A _______ is a constant that allows a portion of memory to be shared by different  types of data

A.  field

B.  struct 

C .union

D. array

10. It is______ error to use a variable before it has been assigned a value

A .compile time

B.   runtime 

C.   logic

D.  No error


11. Output of the following program main (int i=0, switch() ( case 0: case 0:printf(hi);)) 

A. hihi

B. run time error 

C. compile error

D. hi

12. Which of the following performs division by 22

A <<

B. >>

C.|| 

D. ^

13. Output of the following program #include<stdio.h> int main() ( int a-10,b-20,c-30, if(c>b>a) printf(true); else printf(false); return 0.)

A.  True

B.  Compiler error

C.  False

D. 1/0


14. What is order of execution of given for loop? For(1,2,3) (4) if 2 after one iteration becomes false 

A 3,4,1,2,2

B. 2,1,4,3,2 

C 1,2,4,3,2

D 1,4,3,2,2

1. Output of the following program main() (unsigned int -65000, while(i++1=0); printf), return 0,)

A.   0

B.   run time error

C.   I

D.  infinite loop


2 Output of the following program main() { int i-0, if(-0) ( printf(hello), continue, )) 


A hello  

B.   compile time error

C.   hello is printed infinite times

D.  varies

3. Output of the following program main() (int i=0, switch(t) ( case 0: case @printf(hi), )) 

A. hihi

B.hi

C.   compile error

D.  run time error

4. Primary Storage is also known as

A Secondary Memory

B.  Cache Memory

C.  Main Memory

D Auxiliary Memory

5. Output of the following program #include<stdio.h> int main() (int-3; printf%d(++)++); return 0;)

A  4

B  .compile time error

C.   3

D.  5


6. A compound statement


A block

B.   composite statement 

C.   complex statements

D.  body

7. Output of the following program: #include<stdio h> int main() (register inti-10, int “ptr&I, printf(d,”ptr), return 0,)

A .may generate runtime error

B. prints 0 on all compilers  

C. may generate compiler error

D. prints 10 on all compilers


10. Output of the following program: main( typedef auto int a-10, printf(“%d,a), )


A error

B.   a

C.   100

D.  10

11. The case label in switch case is___expression

A.   static

B.   dynamic

C.   variable.

D.  contest


12. Output of the following program: main(( printf%c,5[Geeks Quiz]). )

A.Q

B .runtime error

C.   compile time error

D.  S


13. C allows the identifier length upto_characters long

A 31

B.   63

C.   32

D.  64


1. Output of the following program main() (Unsigned int a-0xffff, a. printf(x,a). 


A ddfd 

B. ffff

C.   00ff

D.  0000

2. Output of the following program int I, main() (ift), else printfielse), return 0;)

A.   if block executed

B.   else block executed

C.   run time error

D.  compile time error

3. Output of the following program: main()( typedef struct tag( char s[10], int a, )har, har

hl,h2-(IHeip, 10); hl-h2, hl. Str[1]-h, printf(“%s %d,hl str.hl.a)

A Thelp, 10

B.   IHelp,0

C.   IHelp,101

D.  ERROR


4. Output of the following program: main(( print%d,printf(Hello)); ) 


A. Hello 16

B.   Hello 4

C.   Hello Hello

D.  Hello 8

5. C allows the identifier length upto__characters long

 A 32

B.   31

C.   64

D.  63


6. Output of the following program typedef struct (int A, char B. char C. )info, Main()( printf(“%d,sizeof(info)), )


A .8

B.   10

C.   12

D.  14


7. Output of the following program main()( printf(“%c,5[Geeks Quiz]);)

A compile time error

B.   Q

C.   runtime error

D.  S


8. In C, the ampersand is also called____ Operator 


A.indirection.

B.   unidirection

C.   inaddress

D.  address


9. How many times will the following for loop run? For mnt 1;<10;++)()

         A 9                     B. 11 

         C. 10.

         D. 8

10. Output of the following program: include<stdio.h> int main() (int x>5, int *const ptr&x, ++(“ptr); printf(“%d, x), return 0; )

A 5 

B.   6

C.   comple error

D.  runtime error

11. Output of the following program #include<stdio.h> int main() { printf%d,sizeof(printf(“%d,7))).) Assume size of integer is 4 bytes

A  .74

B  .47

C.4

D.7

1. A is a constant that allows a portion of memory to be shared by different types of data 

A.struct

B.   array

C.   field

D.  union

2 Output of following #include<stdio.h> int var-20, int main() (int var var, printf%d,var); return 0,)

A.  20

B.  Compile error

C.0

D. Garbage value

3. sprintf) is a  ____ function

A one to many 

B.   one to one

C.   many one

D.  many to many

4. What are the 3 types of looping structures?

A infinite,count nested

B. while, for do

C count up.count down, infinite 

D. count, sentinental-controlled,rerult controlled

5. Output of the following program: #include<stdio.h> int main() (int x>5, int *const ptr&x, ++(*ptr), printf("%d, x); return 0;)

A.   runtime error

B.   6

C.   5

D.  compile error

6. If divisions of decimals are involved in a program, these numbers are stored in

A.   Original Numbers

B.   Irrational Numbers

C.   Rational Numbers

D.  Real Numbers

7._____  doesnt need any semi colon associated with it

A  .return

B  .expression

C. null

D compound


8. Char a[100][100], Assuming that main memory is byte addressable, array is stored starting from memory address 0,address of a[40] [50] is

A  4050

B  5040

 C 5050

D. 4040


9. Output of the following program #include<stdio.h> int main(){ printf%d, sizeof(printf("%d.7)))) Assume size of integer is 4 bytes


A 4

B.  74

C.  47 

D. 7

10. struct( short s[5], union( float y, long z, Ju; )t, Assume that object of type short, float & long occupy 2 bytes,4 bytes,8 bytes respectively Memory of tis

A 18B

B. 22B

C 14B

D. 10B


11. One's complement can be performed by using

A.'

B.&. 

C. I

D. ^

1. Scanf requires___ addresses I the address list

A  high level

B  constant

C. variable 

D. low level

2. Output of the following program typedef struct ( mnt. A, char B; char C. )info. Main()(printf(d,sizeof(info)).)

A.   10

B.   12

C.   8

D.  14

3. Output of the following program: main()( union v( int I, char c[2]: ), Union v val; val: c[0]-A, vai c[1]-B, printf%c, %c %d,val c[0],val c[1].vali), )

A AB,16961

B.   B.B.66.

C.   A,B,32

D.  A.B.0

4. Output of the following program: main(( printf(5+ Geeks Quiz); )

A Error 

B.   Geeks Quiz

C.   Quiz

D.  1005


5. Output of the following program: main( (int a-1,6-0, b+++++; printf%d%d,a,b);) 


A 36

B.   34

C.   compiler dependent

D.  33

7. sprintf() is a______ function

A.  one to one

B.  many to many 

C. many to one

D. one to many

8. Output of the following program: main() { int i-0-0; while(<5j<10) (++I;j++) printf(“%d,”%d,1)); )

A 510

B.   syntax error

C.   55

D.  10 10

9. Which of the following has highest conversion rank?

A long long  

B. long double

C char

 D. long

10. Output of the following program #include<stdio.h> Int main() (typedef static int *, intj, I a- &j, printf(“%d, “a); return 0,)

A garbage value

B. runtime error 

C. compile error

D.0


11.Array is_____ a datatype


A.   Derived

B.   Basic, Derived

C.   Primitive

D.  Basic

12. Which of following is not a character classification in c language?

A ASCII

B. digit C. control.

D graphical

13. By default a floating constant is of_____ data type header file.

A. long 

B. long double

C.   float

D.  double


14. Output of the following program for(0,1<4;i++) printf(“%d,i&1),

A 0000

 B. 0101

C.1111

D. 1010


1. Getting the program into memory known as the the function of an operating system program 


A. Linker 

B.   Loader

C.   Compiler

D.  Text-editor

2. Output of the following program union test (int x, char arr[4], int y.); int main() (uniontest t, t.x-0, Larr[1]-G, printf(“%s,tarr), ) Assume, size of (char)-1 sizeof(int)=4 

A nothing printed

B.   error

C.   G

D.  garbage value


3. How will you print \n on screen? 


A .print(\n),

B.  print\\n).

C.  print(\n), 

D. echo in,

4. Output of the following program typedef struct (int A, char B, char C, )info; main( print%d,sizeof(info)); }

A 12 

B.   8

C.   14

D.  10


5. What is order of execution of given for loop? For(1:2,3) (4) if 2 after one iteration becomes false 


A 1,4,3,2,2

B. 1,2,4,3,2

C 3,4,1,2,2

D. 2,1,4,3,2

6. Output of the following program: #include<stdio.h> int main() { int I; -1,2,3; Printf(“%d.), )

A 2

B.   3

C.   error

D.  1

7. int main() (int -1024; for(;I;i>>-1) printf(hi);) How many times hi printed?

A .11

B.  infinite

C.  10

D.0

8. Output of the following program main() (int i=0, switch(1) (case 0: case 0 printf(hi);)) 


A .run time error

B.   hihi

C.   hi

D.  compile error

9. Consider the following two C lines 1: int var1, 2: extern int var?, Which of the following statements is correct?

A.   1 defines & declares varl,but second statement only declares var2

B.   both statements declare define vanables varl &var2 

C.   both statements only declare variables and don’t define them

D.  2 defines & declares var2,but 1 only declares var 11

10. Char a[100] [100], Assuming that main memory is byte addressable, array is stored Starting from memory address 0,address of a[40][50] is

A 4050

B.   5040

C.   4040

D.  5050

11. Output of the following program: main() (char p; char buff[10]-(1,2,3,4,5,6,9,8). Pbuf+1)[5], printf(“%d/n.p), )

A.  9

B.  5

C .none

D. 6

1. How will you print \n on screen?

A .echo in

B. print(\\n).

C.print(\n).

 D. print(\n),

2. Output of the following program: main( printf(5+ GeeksQuiz); )

A.   1005

B.   Quiz

C.   Error

D.  Geeks Quiz

3. Output of the following program #include<stdio.h> Int main() (typedef static int*I, int j. I a=&j. printf(“%d, “a ); return 0; }

A.garbage value

B.  0

C.  runtime error 

D. compile error


4. Output of the following program main() (int a[5], printf(“%u,&a+1); }

A.   2020

B.   2022

C.   2040

D.  2004

5. It is_____ error to use a variable before it has been assigned a value

A.   runtime

B.   No error

C.   compile time

D.  logic

6. A negative number x is stored in memory as

A -x

B. ¹-1  

C.+01

D. x+1


7. _______ is responsible for executing instructions such as arithmetic calculations,comparisons among data and movement of data inside the system.

A.   CPU

B.   Input Devices

C.   Auxiliary Storage Devices

D.  Output Devices


8. How many times will the following for loop run? For(int i=1;i<10;i++)( ) 


A. 10

B.   8

C.   11

D.  9

9. Output of the following program union test (int x, char arr[4]; int y.); int main() (union

test t, tx-0, tarr[1] G, printf(“%s,tarr),) Assume, size of (char)=1 sizeof(int) 4

A.   garbage value

B.   G

C.   error

D.  nothing printed


10. A_____  is a constant that allows a portion of memory to be shared by different types of data 


A. array

B.  struct

C.  union 

D. field

11. Output of the following program #include<stdio.h> int main() { int a-10,b-20,c-30; if(c>b>a) printf(true); else printf(false); return 0; )

A.   False

B.   True

C.   1/0

D.  Compiler error


1. int main() (inti-1024, for(-1) printf(hi), ) How many times hi is printed? 


A 0

 B. 10

C infinate

D. 11

2. Output of the following program for(i=0;i<4j++) printfdi&1),

A 0000

B.   0101

C.   1010

D.  1111


3. Number of bytes in memory taken by below structure? Struct test( int k, char c; );


A.  integer size + character size

B.  multiple of wordsize

C: integer size multiple

D. platform dependent

4. Output of the following program #include<stdio.h> int main() (register int -10, int *ptr&I; printf(“%d, *ptr); return 0,)

A. prints 0 on all compilers  

B. may generate compiler error

C.   may generate runtime error

D.  prints 10 on all compilers


5. struct( short s[5], union( float y, long z, ju, )t, Assume that object of type short, Float & long occupy 2 bytes,4 bytes,8 bytes respectively Memory oft is


A 18B

B.   22B

C.   14B

D.  10B

6. Output of the following program #include<stdio.h> int main() (int i=(1,2,3). Printf(“%d,i), return 0,)

A 2

B.   1

C.   garbage value

D.  3

 

7. C allows the identifier length upto characters long

A.   63

B.   31

C.   32

D.  64

8. The integral data types of C can be further divided into categories

A 4

B. 3

C.5 

D. 2


9. int main() (int-1024, for(ii>>=1) printf(hi), ) How many times hi is printed? 


A 0 

B  infinite

C  10

D. 11

10. Output of the following program: float 2.0, float j-1.0; float sum-0.0, main() (

while(0.001) (jj, sum-sum+(); printf(“%fin, sum);))

        A. 10             B.9         C. 11         D. 8


11. Output of the following program #include<stdio.h> int main() { printf(“%d,sizeof printf%d,7))); ) Assume size of integer is 4 bytes


        A. 4               B. 47                C. 7                  D. 74


12. Output of the following program #include<stdio.h> int main() { int x>5, int *const ptr&x, ++(*ptr), printf(“%d, x), return 0,)

        

        A .compile error                      B. 5           C. 6     D.runtime error


13. Output of the following program: #inchade<stdio.h> int main() (int x>5, int “const ptr&x, ++(“ptr), printf%d, x), return 0,)


A compile error                       B. 5               C. 6      D. runtime error


14. Output of the following program, union test (int x, char arr[4], int y.), int main() (union test 1, 1-0, tarr[1]-G, printf%s,t arr), ) Assume, size of (char)=1 sizeof(int) 4 

A .error            B.G      C. nothing printed     D. garbage value

15. How many times is a do while loop guaranteed to loop 

A infinitely B. 0             C. cant say       D. I

16.______ languages uses symbols, or mnemonics, to represent the various machine language instructions as delimiter.

A. High-level B. Machine        C. Compilation         D. Assembly


17. Internally a string is stored having

A \2                  B. \1                C. \0                D. \n


18. Output of the following program: main() (printf(x,-1>>1), return 0,)

A fff0            B f0ff                C.0fff         D. ffff


19.  Output of the following program typedef struct (int A; char B, char C. ) info; main() { printf%d,sizeof(info)), ) 


    A. 8        B. 14    C. 10 D. 12



20.  Output of following #include<stdio.h> int var-20, int main() { int var var.printf(“%d,var); return 0, ). 

            A. 0                                            B. 20

            C. Garbage value                 D. Compile error


1. Output of the following program: main() (int i-0, if(-0) (printf(hello).continue, ))


A .compile time error         B. hello is printed infinite times

C. hello            D. varies


2. C allows the identifier length upto characters long 

        A. 64          B. 63         C. 31         D. 32


3.  If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the variable should be declared as 

    A extern           B. static        C. volatile        D. const


4.  Which of the following is not derived type?

A enumerated             B. float         C. arrays          D. pointers 


5. Which of following statement about pretest loop is true?

    A.   If pretest loop limit test is false, the loop executes one more time.

    B.   Pretest loop initialization is done first in body.

    C.   Pretest loops execute a minimum for one time.

    D.  The update for pretest loop must be part of loop body.


6. Output of the following program: #include<stdio.h> int main() (int(1,2,3), printf(“%d,i), return 0,)

A. 1       B. 3         C. garbage value          D. 2


7. Output of the following program: main() (Unsigned int a-Oxffff, ‘a; printf(%x,a);

A. ddfd             B. 00ff             C. 0000         D. ffff


8. How many times will the following for loop run? For(int i=1;i<10;i++)()

A 10                 B.9                C. 8      D. 11


9. Output of the following program main) (char p. char buf[10]-(1,2,3,4,5,6,9,8); pe(buf+1)[5], printf(“%d/n,p), )

A. none            B 6       C. 5      D .9

10. Structure is a

A collection of elements of different datatype

B.   collection of elements with same value

C.   collection of elements/only a element

D.  collection of elements of only same data types


11. The library function used to find last occurrence of character in string is


A. strnchr()        B. strstr           C. strnstr         D. laststr 


12. Which header file you need to include to use typecasting?

A stdio.h          B. ctype h                 C. math h        D. string h


6.________ statement doesn’t need any semi colon associated with it 


A .compound              B. return         C expression  D. null


7. In C static storage class cannot be used with


A Function parameter          B. Function name

C. Local variable                     D. Global variable



8. Output of following include<stdio.h> int var-20, int main() (int var-var,print%d, var), return 0,)

A .0                  B. 20                C. Compile error         D. Garbage value.


9 Output of the following program for(-0,1<4;i++) printf&1),

A .1111            B. 0101                     C. 0000            D. 1010



10._______ is responsible for executing instructions such as arithmetic calculations, comparisons among data and movement of data inside the system

A. Auxiliary Storage Devices  B. CPU           C. Input Devices          D. Output Devices

11. Two way selection is implemented with_____ Statement

A. else if          B. switch                      C.ifelse         D. case


12. Which of the following for down given scanf() is true? Scanf(“E,str),

A. reads exactly 4 characters             B. reads minimum 4 characters

C. reads nothing                                  D. reads multiples of 4 characters


13. struct( short s[5], union( float y, long z, Ju, )t, Assume that object of type short, float & long occupy 2 bytes,4 bytes,8 bytes respectively Memory oft is

A. 14B              B. 10B              C 18B                        D. 22B


19. Output of the following program #include<stdio.h> int main() (int i-(1,2,3), printf%d,a), return 0,)

A. 2       B .3              C. 1      D. garbage value



20. int main() (inti-1024, forti>>-1) printf(hi). ) How many times hi is printed?


A .0      B. 11             C. infinite        D. 10

1. Which of the following can be efficiently used with less no of tokens to read input? A. for, while B. for C. repeat   D. while

21. Conversion specification given in printf() is of the format

A %Minwidth Flag Precision code size            B. %Code Precision Flag

C. %Precision Minwidth Flag code                   D. %Flag Minwidth Precision size code


22. Output of the following program: main() (int a[5], printf(“%u,a+1), )


A. 2004                     B. 2020            C. 2002                        D. Lvalue required


23. Output of the following program: union test (int x, char arr[4], int y, ); int main() (union test 1, 1-0, tarr[1] G, printf(“%s,t arr); ) Assume, size of (char)-1sizeof(int)-4


A. nothing printed                   B.G      C error        D.garbage value


24. Output of the following program: main(){ printf(5+ GeeksQuiz), )


A Geeks Quiz B 1005  C. Error            D. Quiz


25. Output of the following program main() (int a-1,b-0, ba+++++, printf(“%d ,b);) 

A compiler dependent       B. 36    C. 33  D. 34


26. Output of the following program float i-2.0, float j-1.0, float sum-0.0, main() { while(0.001) (j+j, sum-zum+(); printf(“%fn,sum), ))

A 11 B. 8       C 10     D. 9


27. If only one memory location is to be reserved for a class variable no matter how many objects are instantiated, then the variable should be declared as

A const             B. volatile        C. extern         D. static


28.  Which of the following performs division by 27 

A.^    B. >> C. II       D. <<


29.  How will you print in on screen?

A echo In                     B. print(\n);     C. print(\\n).             D. print(n);


17. (1101)2=(?)10

A 26                 B. 15    C. 3      D. 13

18. Output of the following program: main() (int i=0; if(-0) (printf(hello), continue;))

A hello is printed infinite times          B. hello

C. varies                                  D. compile time error


netaji gandi

NPTEL Programming in Java Jan 2024 Week 11

  Week 11 : Programming Assignment 1 Due on 2024-04-11, 23:59 IST The following code is missing some information needed to run the code. Add...