intro to c

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Suppose a,b,c are integer variables with values 5,6,7 respectively. What is the value of the expression: !((b+c)>(a+10)) (A) 1 (B) 6 (C) 15 (D) 0

(A) 1 Description : 1.!((b+c)>(a+10)) 2. !((6 + 7) > (5+10)) 3. !(13 > 15) 13 is less than 15 so it will return False (0 ). 4. !(0). Not of 0 is 1.

What the below statement will print if a=10 printf("%d %d",a, !a++); (A) 11 0 (B) 10 10 (C) 10 0 (D) 0 10

(A) 11 0 Values in the function get passed from right to left. First !a++ get processed which pass zero as argument and make a equal to 11

What value of c will get printed main() { int a,b,c; a=10; b=20; c=printf("%d",a)+ ++b; printf("\n%d",c); } (A) 23 (B) 22 (C) 30 (D) Compilation Error

(A) 23 printf() will return no. of bytes it printed Expression becomes c = 2 + ++b; then value of b is incremented before addition

What value of c will get printed main() { int a, b, c; a = 10; b = 20; c = printf("%d",a) + ++b; printf ("%d",c); } (A) 23 (B) 22 (C) 30 (D) Compilation Error

(A) 23 Description : printf() will return no. of bytes it printed. Expression becomes c = 2 + ++b; then value of b is incremented before addition.

What will be the output main() { int i; i = 10; printf("%d\t",5,6); printf("%d", i , i++); } (A) 5 11 (B) 6 10 (C) 6 11 (D) 5 10

(A) 5 11 Description : Value in a function get passed from right to left. First i++ get passed and it make i = 11.

What will be the output main() { int i; i = 10; if(i == 20 || 30) { printf("True"); } else { printf("False"); } } (A) True (B) False (C) Syntax Error (D) Run time Error

(A) True i==20 is a expression which will return TRUE or FALSE depending on the value of i. In this program it will return 0 so the statement become If ( 0 || 30) 30 is a nonzero value which means TRUE (1) in C when ORed with 0 will result TRUE.

Given the following program fragment main () { int i, j, k; i = 3; j =2*(i++); k =2*(++i); } which one of the given option is correct? (A) j = 6, k = 10. (B) i = 5, k = 6. (C) j = 6, k = 8. (D) i = 4, j = 6.

(A) j = 6, k = 10. In the expression j = 2 * (i++) the value of i is used before incrementing and in expression k =2*(++i); will get incremented first and then used in the expression

How many times the below loop will get executed? main() { int i,j; i = 10; for (j=i==10 ; j<=10 ; j++) { printf("\n%d",j); } } (A) 1 (B) 10 (C) 11 (D) Compilation Error

(B) 10 Description : Expression i ==10 return 1 and j get initialized to 1.

What will be printed as the result of the operation below: main() { int x=5; printf("%d,%d,%d",x,x<<2,x>>2); } (A) 5,21,1 (B) 5,20,1 (C) 5,19,0 (D) 5,19,1 Answer : 5,20,1

(B) 5,20,1

What will be the output main() { int i, j, *ptr, *ptr1; i = 10; j = 10; ptr = &i; ptr1 = &j; if(ptr == ptr1) { printf("True"); } else { printf("False"); } } (A) True (B) False (C) Syntax Error (D) Run time Error

(B) False In this program we are comparing the addresses contained by ptr & ptr1 not the value at those addresses and pointers ptr and ptr1 have the addresses of different variables so above condition is false

What will be the output main() { if(1,0) { printf("True"); } else { printf("False"); } } (A) True (B) False (C) Compilation Error (D) Run time Error

(B) False comma(,) operator returns the value which at the right hand side of , . if statement become if(0)

How many times the below loop will run main() { int i; i=0; do { --i; printf("%d",i); i++; } while(i>=0); } (A) 1 (B) Infinite (C) 0 (D) Compilation Error

(B) Infinite Description: In every iteration value of i is decremented and then incremented so remains 0 and hence a Infinite Loop

Consider the following program, main () { int i, j; for (i=0, j=5; j >0, i < 10; i ++, j--) printf("pskills.org"); } How many times "pskills.org" will get printed (A) 5 (B) Compilation Error (C) 10 (D) None of the above

(C) 10 Condition part of for loop ( j>0, i<10 ) is separated by commas which means that compiler will use the value which is at right hand side of comma i.e of i<10 so the loop will execute till the value of i is less than 10.

How many times the below loop will get executed? main() { int i; for(i=20, i=10; i<=20; i++) { printf("\n %d", i); } } (A) 1 (B) Run time Error (C) 11 (D) Compilation Error

(C) 11 i will start from 10

switch(option) { case 'H' : printf("Hello"); case 'W' : printf("Welcome"); case 'B' : printf("Bye"); break; } what would be the output if option = 'H' ? (A) Hello (B) Hello Welcome (C) Hello Welcome Bye (D) None of the above

(C) Hello Welcome Bye If option = H then the first case is true so "Hello" gets printed but there is no break statement after this case to come out of the switch statement so the program execute all other case statements also and Hello Welcome Bye get printed.

What the below statement will print if a=10 and b = 20? printf("%d",a==b); (A) 20 (B) 10 (C) 1 (D) 0

(D) 0 Description : a==b is a expression and will return 1 (true) or 0 (False) depending on the values of a and b. Here a and b are not equal so 0 is printed.

How many times the below loop will get executed? main() { int i; for(i=9;i;i=i-2) { printf("\n%d",i); } } (A) 5 (B) 6 (C) Compilation Error (D) Infinite

(D) Infinite Above loop will iterate till i have non zero value. Initial value of i is 9 and it get decremented by 2 in every iteration ( 9, 7, 5, 3, 1, -1, -3 â?¦.). Value of i will never become 0 and loop will run infinitely.

How many times the while loop will get executed? main ( ) { int a = 1 ; while ( a <= 100) ; { printf ( "%d", a++ ) ; } } (A) 100 (B) 1 (C) 0 (D) Infinite

(D) Infinite Description : Loop will execute infinite no of times because of the ; at the end while loop.

What will be the output of the following program? main() { printf(3+"Proskills"+4); } (A) Compilation Error (B) skills (C) kills (D) ls

(D) ls Proskills is a constant string and statement printf(3+"Proskills"+4); will skip seven(3 + 4) characters of the string before printing.

Linker generates ___ file. A - Object code B - Executable code C - Assembly code D - None of the above.

(b). Linker links the object code of your program and library code to produce executable.

What will be the output of the following program if the base address of array is 100. main() { int gyan[] = { 1,2,3,4,5 }; int i,*ptr ; ptr = gyan; for(i = 0; i<=4 ; i++) { printf("\n %d", *ptr++); } }

1 2 3 4 5 ptr contains the base address of the array and printf() is printing the value at the current address contained by ptr and then incrementing the pointer to point to the next array element address.

What will be output of the following c program? #include "stdio.h" int main() { int _ = 5; int __ = 10; int ___; ___ = _ + __; printf("%i", ___); return 0; }

15 Variable name can have only underscore

What will be output of following program? #include<stdio.h> int main() { int a = 320; char *ptr; ptr = (char *)&a; printf("%d",*ptr); return 0; }

64 As we know int is two byte data byte while char is one byte data byte. Character pointer can keep the address one byte at time. Binary value of 320 is 00000001 01000000 (In 16 bit) Memory representation of int a = 320 is: So ptr is pointing only first 8 bit which color is green and Decimal value is 64.

What is the output of the following program? #include<stdio.h> void f() { printf("Hello\n"); } main() { ; } A - No output B - Error, as the function is not called. C - Error, as the function is defined without its declaration D -Error, as the main() function is left empty

A - No output No output, apart from the option (a) rest of the comments against the options are invalid.

Which statement can print \n on the screen? A - printf("\\n"); B - printf("n\"); C - printf("n"); D - printf('\n');

A - printf("\\n"); Option A is the correct answer. In C programming language, "\n" is the escape sequence for printing a new line character. In printf("\\n"); statement, "\\" symbol will be printed as "\" and "n" will be known as a common symbol.

What will be the output of the following program? main() { printf("%c","Pskills"[4]); }

Answer : l Description : Pskills is a constant string and character at index 4 will get printed

Similarity between a structure, union and enumeration, A - All are helpful in defining new variables B - All are helpful in defining new data types C - All are helpful in defining new pointers D - All are helpful in defining new structures

B - All are helpful in defining new data types

The prototype of a function can be used to, A - Define a function B - Declare a function C - Erase a function D - None of the above

B - Declare a function Prototype of a function can be used to declare a function. It is necessary in order to provide information (return type, parameter list and function name, etc) about the function to the compiler.

The correct order of mathematical operators in mathematics and computer programming, A - Addition, Subtraction, Multiplication, Division B - Division, Multiplication, Addition, Subtraction C - Multiplication, Addition, Division, Subtraction D - Mathematical operators can be done in any order

B - Division, Multiplication, Addition, Subtraction (BODMAS)

In the given below code, the P2 is Typedef int *ptr; ptr p1, p2; A - Integer B - Integer pointer C - Both, Integer & Integer pointer D - None of above

B - Integer pointer Ptr is an alias to int*.

A local variable is stored in ___ A - Code segment B - Stack segment C - Heap segment D - None of the above

B - Stack segment All the local variables are stored in a memory called as stack.

Choose the correct statement that is a combination of these two statements, Statement 1: char *p; Statement 2: p = (char*) malloc(100); A - char p = *malloc(100); B - char *p = (char*)malloc(100); C - char *p = (char) malloc(100); D - None of the above

B - char *p = (char*)malloc(100); ptr = (data type *)malloc(size); The given above code is a prototype of malloc() function, where ptr indicates the pointer. char *p = (char*)malloc(100); In this code, "*p" is a pointer of type char and malloc() function allocates the memory for char.

Which of the following functions disconnects the stream from the file pointer? A - fremove() B - fclose() C - remove() D - file pointer to be set to NULL

B - fclose()

What is the built in library function to compare two strings? A - string_cmp() B - strcmp() C - equals() D - str_compare()

B - strcmp() strcmp() is the built in function from "string.h" to compare two strings. Returns 0 if both are same strings. Returns -1 if first < second string. Returns 1 first > second.

If your program gets an error when dividing by zero, this type of error is called? A. syntax B. run-time C. undetected D. logic

B. run-time

How many times the given below program will print "India"? #include<stdio.h> int main () { int x; for(x=-1; x<=20; x++)int i; { if(x < 10) continue; else break; printf("India"); } A - Unlimited times B - 21 times C - 0 times D - 20 times

C - 0 times Following for loop there is only one statement, that is int i; break & continue are appearing out side for block which is compile error #include<stdio.h> int main () { int x; for(x=-1; x<=20; x++)int i; { if(x < 10) continue; else break; printf("India"); }

Which of the following variable cannot be used by switch-case statement? A - char B - int C - float D - Double

C - float Switch Case only accepts integer values for case label, float values can't be accepted in case of Switch Case.

What will be output when you will execute following c code? #include<stdio.h> { char arr[11]="The African Queen"; printf("%s", arr); return 0; }

Compilation Size of any character array cannot be less than the number of characters in any string which it has assigned. Size of an array can be equal (excluding null character) or reater than but never less than

The correct order of evaluation for the expression "z = x + y * z / 4 % 2 - 1" A - * / % = + - B - / * % - + = C - - + = * % / D - * / % + - =

D - * / % + - = * / % holds highest priority than + - . All with left to right associativity

What is the output of the following program? #include<stdio.h> main() { struct student { int num = 10; }var; printf("%d", var.num); } A - 10 B - Garbage C - Runtime error D - Compile error

D - Compile Error Structure elements cannot be initialized

What is the output of the following program? #include<stdio.h> void main() { char s[] = "C++"; printf("%s ",s); s++; printf("%s",s); } A - C++ C++ B - C++ ++ C - ++ ++ D - Compile error

D - Compile error 's' refers to a constant address and cannot be incremented.

What is the output of the following program? #include<stdio.h> main() { printf("\"); } A - \ B - \" C - " D - Compile error

D - Compile error Compile error, Format string of printf is not terminated.

Choose the invalid predefined macro as per ANSI C. A - __FILE__ B - __DATE__ C - __TIME__ D - __C++__

D - __C++__ There is no macro define with the name __C++__, but __cplusplus is defined by ANSI)

How many times main() will get called? main() { printf("\n Main Called Again"); main(); }

Infinite There is no condition in the main() to stop the recursive calling of the main() hence it will be called infinite no of times.

Which of the following program structure/component/statement is not an example for implementation of modularization ?

type casting Option c) type casting. DLL and Functions help in modularization of a program while typecasting just converts from one data type to another.


संबंधित स्टडी सेट्स

organic chemistry test 2 - worksheet 6

View Set