exam2

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following function, that finds the length of a string, is correct? A int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); } B int xstrlen(char s) { int length=0; while(*s!='\0') length++; s++; return (length); } C int xstrlen(char *s) { int length=0; while(*s!='\0') length++; return (length); } D int xstrlen(char *s) { int length=0; while(*s!='\0') s++; return (length); }

A

Which of the following statements are correct about 6 used in the program? int num[6]; num[6]=21; A. In the first statement 6 specifies a particular element, whereas in the second statement it specifies a type. B. In the first statement 6 specifies a array size, whereas in the second statement it specifies a particular element of array. C. In the first statement 6 specifies a particular element, whereas in the second statement it specifies a array size. D. In both the statement 6 specifies array size.

B

Which of the statements is correct about the program? #include<stdio.h> int main() { int i=10; int *j=&i; return 0; } A. j and i are pointers to an int B. i is a pointer to an int and stores address of j C. j is a pointer to an int and stores address of i D. j is a pointer to a pointer to an int and stores address of i

C

What is the output of this C code? Memory location assumption x:1000 ptr:2000 void main() { int x = 0; int *ptr = &5; printf("%p\n", ptr); }

Compile error

What will be the output of the following program? #include<stdio.h> void main(void) { char a[ ] = "3211"; char *p = "EGN"; a = "EGN"; p = "3211"; printf("%s %s\n", a, p); }

Compile error. Cannot reassign string to existing array

What will be output of the following program, if any? #include<stdio.h> void main(){ int a=10; if(10==a){ printf("true"); } else{ printf("false"); } }

True

Comment on the following? const int *ptr;

You cannot change the value pointed by ptr

void main(){ int i=0; for(i;i<=2;--i){ printf(" %d",i); ++i; } }

Zeros continously

What is the output of this C code? void main() { int x = 4 + 4 - 4 * 4 ; printf("%d\n", x); }

-8

What will be output when you will execute following c code? #include<stdio.h> void main(){ int x[10]={5}; printf("%d %d",x[1],x[9]); }

0 0

What is the output of this C code, if any? void main() { int i = 0; int x = ++i, y = i++; printf("%d % d\n", x, y); }

1 1

What is the output of this C code? int main() { int *ptr, a = 10; ptr = &a; *ptr += 1; a++; printf("%d,%d", *ptr, a); }

12,12

What will be the output of the following program, if any? void main(){ int ABC=10, sum=40; ABC = sum * 3; printf("%d",ABC); }

120

What is the output of this C code? Memory location assumption x:1000 ptr:2000 int x = 0; void main() { int *ptr = &x; printf("%p\n", &ptr); ptr++; printf("%p\n ", &ptr); }

2000 2000

What will be the output? #include<stdio.h> void main(){ int data[2][3]={0,1,2,3,4,5}; printf("%d",data[1][0]); }

3

What is the output of this C code? Memory location assumption 1000 - k 2000 - p 3000 - m void main() { int k = 5; int *p = &k; int **m = &p; printf("%d %d %d\n", k, *p, **m); }

5 5 5

What will be output of following program? #include<stdio.h> void main(){ int i = 5 , j; int *p , *q; p = &i; q = &j; j = 5; printf("%d ,%d",*p,*q); }

5, 5

What will be output of the following c program? Choose the best answer. void main(){ int maximum_value=100; int minimum_value=0; int average_value; average_value = (int) (maximum_value + minimum_value / 2); printf("%d",average_value); }

50

void main() { int x = 0; if (x == 0) printf("Its zero\n"); else printf("Its not zero\n"); } You Answe

Its zero

What will be the output of the program ? #include<stdio.h> void main() { char str[20] = "Hello"; char *const p=str; *p='M'; printf("%s\n", str); } UNSURE****

Mello

Will the following functions work? int f1(int a, int b) { return ( f2(20) ); } int f2(int *a) { return (*a); }

No. Because of pointer mismatch

#include<stdio.h> void main(){ int x=4; while(3){ do{ printf("%d",x); } while(0); }; }

Prints 4 continuously

What will be the output of the program ? #include<stdio.h> void main() { int *x; *x=100; printf( " %d",*x); }

Run Time Error

What will be output of following program? #include<stdio.h> #include<string.h> void main(){ char *ptr1 = NULL; char *ptr2 = 0; strcpy(ptr1,"Hello "); strcpy(ptr2,"World"); printf("%s %s",ptr1,ptr2); }

Run time error

What is the output of this C code? int main() { int a = 10, b = 10; if (a = 5) b--; printf("a=%d, b=%d\n", a, b); }

a=5, b=9

#include<stdio.h> int swap(int *x, int *y); int main() { int x=5, y =10; swap(x,y); printf("X is %d Y is %d\n",x,y); } int swap(int *x, int *y) { int temp=*x; // preserve x value in temp *x = *y; // replace x value with y *y = temp; // recall the original x value stored in temp }

compile error

What will be output of the following program, if any? #include<stdio.h> void main(){ if(printf("true")) if(printf("false")); }

true false

What will be output when you will execute following c code? #include<stdio.h> void main(){ int choice=5; switch(choice){ case 1: printf("Coke"); case 2: printf("Tea"); case 3: printf("Coffee); default: printf("Water"); } }

water

int add(int *x); void main() { int x=5, y =5; add(&x); printf("x is %d\n",x); } int add(int *x) { *x = *x + 10; return 5; }

x is 15

int funcB(int x, int y); void main() { int x=10, y=5; funcB(y,x); } int funcB(int x, int y) { printf("x is %d y is %d\n",x,y); return 1; }

x is 5 y is 10


Conjuntos de estudio relacionados

Modules 8 - 10: ACLs and Firewalls Group Exam

View Set

¡Inténtalo!: Subject Pronouns & Present Forms of 'ser'

View Set

Marketing Management Final Review

View Set

Med Surg Chapter 48: Management of Patients With Intestinal and Rectal Disorders

View Set

"Repetition, parallelism, alliteration and antithesis".(For ESOL Students)

View Set

Chapter 48-Diabetes Mellitus (QUESTIONS)

View Set

Splunk core certified user exam questions

View Set

older adult exam 2 practice questions

View Set

Chapter 12: Skin, Hair, and Nails

View Set