PRF192

Ace your homework & exams now with Quizwiz!

Which of the following is not a valid variable name declaration? a) float PI = 3.14; b) double PI = 3.14; c) int PI = 3.14; d) #define PI 3.14

#define PI 3.14

What is the output of this C code? #include <stdio.h> int main() { signed char chr; chr = 128; printf("%d\n", chr); return 0; } a) 128 b) -128 c) Depends on the compiler d) None of the mentioned

-128

what will the code below print when executed? double x=-3.5, y=3.5; printf("%.0f:%.0f\n",ceil(x), ceil(y)); printf("%.0f:%.0f\n",floor(x), floor(y)); a -3:3 -4:4 b.-4:3 -3:4 c.-4:4 -3:3 d.-3:4 -4:3 e.-4:3 -4:3

-3:4 -4:3

what number is equivalent to -4e3? a.-4000 b.-400 c..004 d..0004 e.-40

-4000

what is the output when the sample code below is executed? main() {int i=5; printf("%d\n",i=++i==6) a.0 b.1 c.5 d.6 e.7

1

What is the output of this C code? #include <stdio.h> #include <string.h> int main() { char *str = "x"; char c = 'x'; char ary[1]; ary[0] = c; printf("%d %d", strlen(str), strlen(ary)); return 0; } a) 1 1 b) 2 1 c) 2 2 d) 1 (undefined value)

1 (undefined value)

what is the output when the sample code below is executed? int s=35; printf("%d%d%d",s==35,s+20,s>40) a.1 35 1 b.1 55 1 c.0 55 0 d.1 55 0

1 55 0

what is the output when the sample code below is executed, assuming int data type is 32 bits in size? printf("%d, %d, %d, %d", sizeof(char), sizeof(int), sizeof(10.0), sizeof(10.0f)); a. 2,4,8,4 b. 1,10,10,10 c. 1,4,8,4 d. 1,4,4,4 e. 1,2,4,4

1,4,8,4

what is the output when the sample code below is executed? int calc(int a, int b){ int x,y; x=a+b; y=a*b; return(x+y); } int main(){ int p=3, q=4, r, s; r=calc(p,q); s=calc(q,p); printf("\n%d%d",r,s); return 0;} a. 3 4 b. 17 19 c. 18 18 d. 17 17 e.19 19

19 19

referring to the sample code below, what value will the variable counter have when completed int x=3, counter = 0; while(x-1){ ++counter; x--;} a.4 b.2 c.3 d.0 e.1

2

what is the output when the sample code below is executed? int a[5]={0}, x=2111223; while(x>10){ a[x%10-1]++; x/=10;} printf("%d",a[1]); a.6 b.3 c.1 d.2

2

what is the output when the sample code below is executed? int x=3; if(x==2) x=0; if(x==3) x++; else x+=2; a.5 b.3 c.1 d.4 e.2

2

according to the standard C specification, what are the respective minimum sizes (in bytes) of the following two data type: int and long? a.2,8 b.4,8 c.2,4 d.2,2

2,4

what value will x contain in the sample code below? int x=011|0x10; a.27 b.19 c.25 d.13 e.3

25

What is the maximum value of an unsigned char? a. 128 b. 127 c. 255 d. 256

255

what is the output when the sample code below is executed? int g=1; printf("%d %d %d",g,++g,g++); a.1 3 3 b.1 2 3 c.1 1 1 d.3 3 1

3 3 1

C99 standard guarantess uniqueness of _____ characters for external names. a) 31 b) 6 c) 12 d) 14

31

What is the output of the following C code(on a 64 bit machine)? #include <stdio.h> union Sti { int nu; char m; }; int main() { union Sti s; printf("%d", sizeof(s)); return 0; } a) 8 b) 5 c) 9 d) 4

4

What is the output of this C code? #include <stdio.h> #define MAX 2 enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX}; int main() { enum bird b = PARROT; printf("%d\n", b); return 0; } a) Compilation error b) 5 c) Undefined value d) 2

5

what is the output when the sample code below is executed? int p,q,h; for(p=1;p<=3;p++) for(q=1;q<=2;q++) h=p+q; printf("%d\n",h); a.1 b.5 c.3 d.4 e.2

5

what will be printed when the sample code below is executed? char **buffer="0123456789"; char **ptr=buffer; ptr+=5; printf("%s\n",ptr); printf("%s\n",buffer); a. 56789 0123456789 b.56789 56789 c.0123456789 0123456789 d.5123456789 5123456789 e.0123456789 56789

56789 0123456789

what is the output when the sample code below is executed? int i,j,k,x=0; for(i=1;i<5;i++) for(j=0;j<i;++j){ switch(i+j){ case 0:x=x+1; break; case 1: case 2: case 3: x=x+2; break; }} printf("%d",x); a.12 b.13 c.10 d.8 e.6

6

C99 standard guarantees uniqueness of ____ characters for internal names. a) 31 b) 63 c) 12 d) 14

63

what is the output when the sample code below is executed? #include<stdio.h> void main(){ int i,j=25; int **pi, ***pj=&j; ***pj=j+5; i=*pj+5; pi=pj; **pi=i+j; printf("%d%d",***pi,*pj);} a.30 35 b.65 65 c.60 60 d.25 30 e.60 65

65 65

What is the output of this C code? #include <stdio.h> enum birds {SPARROW, PEACOCK, PARROT}; enum animals {TIGER = 8, LION, RABBIT, ZEBRA}; int main() { enum birds m = TIGER; int k; k = m; printf("%d\n", k); return 0; } a) 0 b) Compile time error c) 1 d) 8

8

What is the output of this C code? #include <stdio.h> int main() { int var = 010; printf("%d", var); } a) 2 b) 8 c) 9 d) 10

8

given the below code int a=1; int i=7; if(a||i++) i++; printf("%d",i); what is the output a.7 b.8 c.9 d.other

8

what is the output when the sample code below executed? #include<stdio.h> int fn(int v){ if(v==1||v==0) return 1; if(v%2==0) return (fn(v/2)+2); else return(fn(v-1)+3); } int main() { printf("%d\n",fn(5)); return (0); } a.6 b.9 c.8 d.7 e.5

8

what is the output when the sample code below is executed? int a=8, b=9; if(a%2=b%3) printf("\n%d %d", ++a, b--) a. 8 9 b. 9 9 c.9 8 d. compiler error e. 8 8

8 8

what is the output when the sample code below is executed? int k=0x55; printf("\n%d",k); printf("\n"); a.65 b.75 c.55 d.85

85

what is the output when the sample code below is executed? int i=3; switch(i){ case 3: i+=5; if(i==8){ i++; if(i==9) break; i*=2;} i-=4; break; case 8: i+=5; break; default: i+=6; break; } printf("%d\n",i); a.8 b.11 c.7 d.9 e.10

9

What is the output of this C code? 97.000000 #include <stdio.h> int main() { float x = 'a'; printf("%f", x); return 0; } a) a b) run time error c) a.0000000 d) 97.000000

97.000000

char name[31]; scanf("%[a-zA-Z0-9]",name); which is the correct statement about the above code? a. Accepts only lower case letters (in the range between 'a' and 'z') upper case letters (in the range between 'A' and 'Z' ) and digits (in the range '0' and '9') b. Accepts only characters except lower case letters (in the range between 'a' and 'z') upper case letters (in the range between 'A' and 'Z' ) and digits (in the range '0' and '9') c. Accepts only spaces lower case letters (in the range between 'a' and 'z') upper case letters (in the range between 'A' and 'Z' ) and digits (in the range '0' and '9')

Accepts only lower case letters (in the range between 'a' and 'z') upper case letters (in the range between 'A' and 'Z' ) and digits (in the range '0' and '9')

What is the problem in following variable declaration? float 3Bedroom-Hall-Kitchen?; a) The variable name begins with an integer b) The special character '-' c) The special character '?' d) All of the mentioned

All of the mentioned

Which is the correct order when listing the following languages from the lowest to the highest level? a. C,Assembly,C++,MATLAB b. Assembly,C,C++,MATLAB c.Assembly,MATLAB,C,C++ d.C,C++,Assembly,MATLAB

Assembly,C,C++,MATLAB

What is the output of this C code? #include <stdio.h> int main() { printf("C programming %s", "Class by\n%s Sanfoundry", "WOW"); } a) C programming Class by WOW Sanfoundry b) C programming Class by\n%s Sanfoundry c) C programming Class by %s Sanfoundry d) Compilation error

C programming Class by %s Sanfoundry

What is the output of this C code? #include <stdio.h> #define a 10 int main() { const int a = 5; printf("a = %d\n", a); } a) a = 5 b) a = 10 c) Compilation error d) Runtime error

Compilation error

Comment on the output of this C code? #include <stdio.h> void main() { int k = 4; int *const p = &k; int r = 3; p = &r; printf("%d", p); } a) Address of k b) Address of r c) Compile time error d) Adress of k + address of r

Compile time error

What is the output of this C code? #include <stdio.h> int main() { const int p; p = 4; printf("p is %d", p); return 0; } a) p is 4 b) Compile time error c) Run time error d) p is followed by a garbage value

Compile time error

What is the output of this C code? #include <stdio.h> int main() { int y = 10000; int y = 34; printf("Hello World! %d\n", y); return 0; } a) Compile time error b) Hello World! 34 c) Hello World! 1000 d) Hello World! followed by a junk value

Compile time error

What is the output of this C code? #include <stdio.h> int main() { printf("Hello World! %d \n", x); return 0; } a) Hello World! x; b) Hello World! followed by a junk value c) Compile time error d) Hello World!

Compile time error

enum types are processed by a) Compiler b) Preprocessor c) Linker d) Assembler

Compiler

Variable name resolving (number of significant characters for uniqueness of variable) depends on a) Compiler and linker implementations b) Assemblers and loaders implementations c) C language d) None

Compiler and linker implementations

Which is false? a) Constant variables need not be defined as they are declared and can be defined later b) Global constant variables are initialised to zero c) const keyword is used to define constant values d) You cannot reassign a value to a constant variable

Constant variables need not be defined as they are declared and can be defined later

What is the size of an int data type? a) 4 Bytes b) 8 Bytes c) Depends on the system/compiler d) Cannot be determined

Depends on the system/compiler

Comment on the output of this C code? #include <stdio.h> void main() { int const k = 5; k++; printf("k is %d", k); } a) k is 6 b) Error due to const succeeding int c) Error, because a constant variable can be changed only twice d) Error, because a constant variable cannot be changed

Error, because a constant variable cannot be changed

what is the output when the sample code below is executed? char fun[]="How are you?"; char **p; p=fun; while(***p!='\0'){ if(strlen(p)!=7) printf("%c",**p); p++;} a. How ar you b.Ho are you c.How re you d.How are you e. How ae you

How ae you

which one of the following is the parameter passed to getchar()? a. It takes no parameter b. Characters to be display c. string variable d. none of the other choices

It takes no parameter

What will happen if the below program is executed? #include <stdio.h> int main() { int main = 3; printf("%d", main); return 0; } a) It will cause a compile-time error b) It will cause a run-time error c) It will run without any error and prints 3 d) It will experience infinite looping

It will run without any error and prints 3

All keywords in C are in a) LowerCase letters b) UpperCase letters c) CamelCase letters d) None

LowerCase letters

What is the output of this C code? #include <stdio.h> int main() { enum {ORANGE = 5, MANGO, BANANA = 4, PEACH}; printf("PEACH = %d\n", PEACH); } a) PEACH = 3 b) PEACH = 4 c) PEACH = 5 d) PEACH = 6

PEACH = 5

Comment on the output of this C code? #include <stdio.h> int main() { int a[5] = {1, 2, 3, 4, 5}; int i; for (i = 0; i < 5; i++) if ((char)a[i] == '5') printf("%d\n", a[i]); else printf("FAIL\n"); } a) The compiler will flag an error b) Program will compile and print the output 5 c) Program will compile and print the ASCII value of 5 d) Program will compile and print FAIL for 5 times

Program will compile and print FAIL for 5 times

For the following code snippet: char *str = "Sanfoundry.com\0" "training classes"; The character pointer str holds reference to string: a) Sanfoundry.com b) Sanfoundry.com\0training classes c) Sanfoundry.comtraining classes d) Invalid declaration

Sanfoundry.com\0training classes

a comment can be split over more than one line, as follows /** A program to calculate average of 5 numbers. **/ a.TRUE b.FALSE

TRUE

the while loop can be written as a for loop a.TRUE b.FALSE

TRUE

Comment on the output of this C code? #include <stdio.h> int main() { int ThisIsVariableName = 12; int ThisIsVariablename = 14; printf("%d", ThisIsVariablename); return 0; } a) The program will print 12 b) The program will print 14 c) The program will have a runtime error d) The program will cause a compile-time error due to redeclaration

The program will print 14

which of the following statement are true with regards to the || operator?(select al correct answer) a.this operator is used to combine two conditional expressions which evaluate to true as a whole only if either of the two expressions evaluate to true. b.only if both the expressions evaluate to false, the outcome is false c.if one of the conditional expressions return false, the outcome is false d.this operator is used to combine two logical expressions which evaluate to true if both individual expression are true

This operator is used to combine two conditional expressions which evaluate to true as a whole only if either of the two expressions evaluate to true. Only if both the expressions evaluate to false, the outcome is false

Variable names beginning with underscore is not encouraged. Why? a) It is not standardized b) To avoid conflicts since assemblers and loaders use such names c) To avoid conflicts since library routines use such names d) To avoid conflicts with environment variables of an operating system

To avoid conflicts since library routines use such names

Which of the following is true for variable names in C? a) They can contain alphanumeric characters as well as special characters b) It is not an error to declare a variable to be one of the keywords(like goto, static) c) Variable names cannot start with a digit d) Variable can be of any length

Variable names cannot start with a digit

Comment on the output of this C code? #include <stdio.h> int main() { char c; int i = 0; FILE *file; file = fopen("test.txt", "w+"); fprintf(file, "%c", 'a'); fprintf(file, "%c", -1); fprintf(file, "%c", 'b'); fclose(file); file = fopen("test.txt", "r"); while ((c = fgetc(file)) != -1) printf("%c", c); return 0; } a) a b) Infinite loop c) Depends on what fgetc returns d) Depends on the compiler

a

Which of the following is a User-defined data type? a) typedef int Boolean; b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays; c) struct {char name[10], int age}; d) all of the mentioned

all of the mentioned

Which is correct with respect to size of the datatypes? a) char > int > float b) int > char > float c) char < int < double d) double > char > int

char < int < double

What is the output of this C code? #include <stdio.h> int main() { printf("sanfoundry\rclass\n"); return 0; } a) sanfoundryclass b) sanfoundry class c) classundry d) sanfoundry

classundry

which one of the following is a valid function definition? a. double funct(int a,b, double c,d) b. double funct(int a,b, double c) c. double funct(char a,b, double d) d. double funct(int a,int b, double c)

double funct(int a,int b, double c)

what is the output when the sample code below is executed? char *ptr="Hello world"; ptr++; printf("%s",ptr); ptr+=2; printf("%s",ptr); a.ello worldllo world b.Hello worldHello world c.ello worldlo world d.ello worldHello world e.Hello worldello world

ello worldlo world

consider the following code: if(a==b) printf("\n the number are equal"); else(a<b) printf("\n the smaller number is: %d",a); else printf("\n the smaller number is: %d",b); in the above code, if a=14 and b=9, then the .... clause is executed a. else b.if c else if

else

Comment on the output of this C code? #include <stdio.h> int main() { float f1 = 0.1; if (f1 == 0.1f) printf("equal\n"); else printf("not equal\n"); } a) equal b) not equal c) Output depends on compiler d) None of the mentioned

equal

Once the function ends, the control is returned back to the ... function and execution continues from the statement immediately after the function call a. executing b.called c.declared d.calling

executing

the operation between float and int would give the result as a. float b. int c. unsigned int d.none of the above

float

what is the incorrect statement about floating-point data types(float and double)? a. computers store floating-point data using separate components, including the mantissa and exponent b.float-point means that the decimal point can float(that is, it can ba placed anywhere relative to the significant digits) c.both data types(float and double) can represent arbitrarily small as well as arbitrarily large numbers d.none of the above

float-point means that the decimal point can float(that is, it can ba placed anywhere relative to the significant digits)

what is the output when the sample code below is executed? int n=10, i; int k=0; for(i=1;i<n;i=i*2)k++; printf("i:%d, k:%d", i, k); printf("\n"); a i:16, k:3 b.i:16, k:4 c.i:16, k:5 d.i:8, k:4 e.i:10, k:4

i:16, k:4

which of the following statements is incorrect? a. if a file opened for writing already exits its content will be overwritten b. if a file is opened for reading it is required that the file must exist c. none of the other d. if a file is opened for writing it is required that the file must exits

if a file opened for writing already exits its content will be overwritten

The format identifier '%i' is also used for _____ data type? a) char b) int c) float d) double

int

Which of the following is not a valid C variable name? a) int number; b) float rate; c) int variable_count; d) int $main;

int $main

Which of the following is not a valid variable name declaration? a) int _a3; b) int a_3; c) int 3_a; d) int _3a

int 3_a

Which of the following is not a valid variable name declaration? a) int __a3; b) int __3a; c) int __A3; d) None of the mentioned

int __a3

declare a two dimensional integer array of two rows and four columns having some initial values a.int arr1[4][2]={{8,12},{22,45},{23,40},{44,79}} b.int arr1[2][4]={{8,12},{22,45},{23,40},{44,79}} c.int arr1[4][2]={{8,12};{22,45};{23,40};{44,79}} d.int arr1[][2]={{8,12},{22,45},{23,40},{44,79}}

int arr1[4][2]={{8,12},{22,45},{23,40},{44,79}}

Which is valid C expression? a) int my_num = 100,000; b) int my_num = 100000; c) int my num = 1000; d) int $my_num = 10000;

int my_num = 100000

in myfile.c does not exist, what will be output of this program? #include<stdio.h> main(){ FILE *fi; fi=fopen("myfile.c","r"); if(fi=NULL) {puts("file is not opened"); exit(1);} else puts("FILE opened");} a. file is not opened b.no output c.FILE opened d.error

no output

Comment on the output of this C code? #include <stdio.h> int main() { float f1 = 0.1; if (f1 == 0.1) printf("equal\n"); else printf("not equal\n"); } a) equal b) not equal c) Output depends on compiler d) None of the mentioned

not equal

what is the output when the sample code below is executed? int i=0; for(;i;) printf("This is a loop"); if(i>0) printf("in C program"); a. nothing b. garbage value c. in C program d.this is a loop in C program e. this is a loop

nothing

a string is a ... array of characters terminated by a null('\0') a.one-dimensional b.two-dimensional

one-dimensional

what is the output when the sample code below is executed? char mess[]="Your are welcome here"; char *p; p=mess; mess[8]='\0'; puts(++p); a.our are wel b.our are c.Your are d.Your are wel

our are

What is the output of this C code (on a 32-bit machine)? #include <stdio.h> int main() { int x = 10000; double y = 56; int *p = &x; double *q = &y; printf("p and q are %d and %d", sizeof(p), sizeof(q)); return 0; } a) p and q are 4 and 4 b) p and q are 4 and 8 c) Compiler error d) p and q are 2 and 8

p and q are 4 and 4

given the below code ? char st[50]; scanf("%5[^\]",st); printf("%s",st); a user enters "pfc is simple" what is printed? a.other b.pfc is c.pfc is so simple d.blank output e.pfc i

pfc i

what does the following declaration mean (if there are more than one correct answers, choose the best one) int *ptr[10]; a.array of 10 integer pointers b.pointed to the array of 10 elements c.array of 10 pointers

pointed to the array of 10 elements

which are the following statements printf % character? a.printf("\%") b.printf("\\%") c.printf("\%%") d.printf("%%")

printf("\%%") printf("%%")

What is the output of this C code? #include <stdio.h> int main() { printf("sanfoundry\r\nclass\n"); return 0; } a) sanfoundryclass b) sanfoundry class c) classundry d) sanfoundry

sanfoundry class

Which of the following function can be used to enter an integer in C program? A) getchar B) gets C) scanf D) None of the others

scanf

which 2 options are correct about the function scanf? a.EOF indicates that scanf filled all addresses successfully b. scanf returns the number of addresses successfully filled of EOF c.return avoid type d.EOF indicates that scanf did not fill any address AND encountered an end of data character.

scanf returns the number of addresses successfully filled of EOF EOF indicates that scanf did not fill any address AND encountered an end of data character.

What is short int in C programming? a) Basic datatype of C b) Qualifier c) short is the qualifier and int is the basic datatype d) All of the mentioned

short is the qualifier and int is the basic datatype

which of the following can be used to append one string at the end of another a.strcpy b.strcmp c.strcat d.none of the above

strcat

Which is NOT a valid data type in C language? A) int B) float C) string D) double

string

Which of the datatypes have size that is variable? a) int b) struct c) float d) double

struct

which one of the following is a variable, which can contain the address of the memory location of another variable?(choose the best answer) a.string b.struct c.array d.pointer

struct

how is a variable accessed from another file? a. the global variable is referenced via the auto specifier b. the global variable is referenced via the extern specifier c. the global variable is referenced via the pointer specifier d. the global variable is referenced via the ext specifier e. the global variable is referenced via the global specifier

the global variable is referenced via the extern specifier

what would happen if the user types in the number 3 and presses Enter when running this program? main(){ int x=5; char c; printf("Enter x="); scanf("%d",&x); printf("Calculate square(Y/N):"); c=getchar(); if(c==Y||c==y) printf("sqr=%d",x*x); } a.sqr=9 b.Its depend on whether the user enters 'Y' or not, being asked "calculate square?" c.sqr=25 d.the program exits without printing the square

the program exits without printing the square

Which data type is most suitable for storing a number 65000 in a 32-bit system? a) signed short b) unsigned short c) long d) int

unsigned short

Which of the following cannot be a variable name in C? a) volatile b) true c) friend d) export

volatile

when does the code block following while(x<100) execute? a.when x is less than one hundred b.when x is equal to one hundred c.when x is greater than one hundred d.while it wishes

when x is less than one hundred


Related study sets

Preparing Effective business plans

View Set

Abdomen: Peritoneum and Peritoneal cavity

View Set

Old Testament Exam 1 Springer Study Guide

View Set

Romantic Period and Restoration Period

View Set

Assignment: Exercise 3.1 (Practice)

View Set