Time: 60 minutes
Question .No: 30
Allowed: pencil + a piece of paper.
1. Given variable declaration below:
int x,y;
int *a, *b;
Which is wrong statement?
a. a=&x;
b. b=&y;
c. b=&a;
d. *b=*a;
2. Given a short code:
int i=1,j=2;
for(;i<5;i++)
i*=j++;
The given code above is:
a. Wrong syntax
b. i=5, j=4
c. i=10, j=4
d. Three answers above are wrong.
3. Given a short code:
int x[]={0x4161}
char *p1, *p2;
p1=(char*) x;
p2=p1+1;
printf(“%c %d”,*p1, *p2);
Result:
a. A 97
b. a 65
c. A 98
d. a 66
4. Given a short code:
int x=1,y=2;
while(x<=10)
{
x++;
if (x==6)
break;
y+=++x;
}
printf("%d %d",x,y);
Result:
a. 6 10
b. 11 37
c. 12 40
d. Three answers above are wrong.
5. Given a short code:
int x=1,y=2;
while(x<=10)
{
x++;
if (x==6);
y+=++x;
}
printf("%d %d",x,y);
Result:
a. 6 10
b. 11 37
c. 12 40
d. Three answers above are wrong.
6. Given a short code:
int x=1,y=2;
while(x<=10)
{
x++;
if (x==6)
continue;
y+=++x;
}
printf("%d %d",x,y);
Result:
a. 6 10
b. 11 37
c. 12 40
d. Three answers above are wrong.
7. Given a short code:
int i=1,j=0;
for(i=1;i<10;i+=2)
for(;i<8;i++)
j+=i;
printf("%d %d",i,j);
Result:
a. 10 28
b. 19 81
c. 11 0
d. Three answers above are wrong.
8. Given a short code:
int i=1,j=0;
for(i=1;i<10;i+=2);
for(;i<8;i++)
j+=i;
printf("%d %d",i,j);
Result:
a. 10 28
b. 19 81
c. 11 0
d. Three answers above are wrong.
9. Given a short code:
int i=1,j=0;
if (i>j);
if (i<5)
i+=3;
else
i+=2;
Result of i:
a. 1
b. 2
c. 3
d. 4
Given a short code( is used for 10,11,12,13,14,15):
#include<stdio.h>
double a,b;
void f1(int a);
int f2(int a);
void f1(int a)
{
int s, i;
for(s=i=0; i<=a; s+=++i)
i+=2;
printf(“%d”,s);
}
int f2(int a)
{
int i;
for(i=2;a%i;i++);
printf (“%d”, i);
if (i==a)
return a;
else
return a/i;
}
10. Invoke f1(15)
a. Print 57
b. Print 63
c. Print 51
d. Three answers above are wrong.
11. Invoke f2(15):
a. Print 3
b. Print 15
c. Print nothing
d. Three answers above are wrong.
12. Invoke f1(f2(39))
a. Print 3 35
b. Print 35
c. Print 335
d. Three answers above are wrong.
13. Invoke f2(f1(39)
a. Print 287
b. Print 35
c. Print 2870
d. Three answers above are wrong.
14. Invoke f2(f2(39))
a. Print 133
b. Print 13 3
c. Print 313
d. Three answers above are wrong.
15. Which one is correct statement?
a. a=b+f1(a);
b. a=b+f2(a);
c. a=f1(f2(b));
d. a=f2(f1(b));
Given a short code:
int a=5, b=6, y;
y=a&&(a>b++)&&--b;
16. Value of b, y are:
a. b=5, y=0
b. b=6, y=1
c. b=7, y=0
d. Three answers above are wrong.
17. Given a short code:
int x=11, y=5, b;
b=(x-y)?(x&&y):(x||y);
Value of b:
a. 14
b. 15
c. 1
d. 0
18. Given a short code:
int a=10, b=7; float y;
y=(b+1)*(a/b);
printf(“%5.2f”,y);
Result:
a. 11.43
b. 11.42
c. 8
d. 8.00
19. Given a variable declaration:
int a,b, *p1, *p2;
Which one is wrong statement?
a. p1=a;
b. p2=&b+1;
c. p1=p2+a;
d. p1=&a+1;
20. Given a variable declaration:
int *p1, *p2, *p3;
Which one is correct statement?
a. p3=p1+p2;
b. p3=p2-p1;
c. *p3=p1-p2;
d. p3=2*p1;
21. Given a short code:
int x=1,i;
for(i=1; i<10; i++)
{
x+=++i;
if(i==5)
break;
}
printf(“%d”,x);
Result:
a. 31
b. 7
c. 55
d. Three answers above are wrong.
22. Given a short code:
int i=1, j=2; float S=0;
do {
S+=i/j;
i++;
j*=2;
} while(i<15);
printf(“%3.2f”, S);
Result:
a. 2.0
b. 2.00
c. 0.00
d. 0.0
23. Given a short code:
int a=1, b=0;
while(a<=b&&++b)
if(a==b)
break;
printf(“%d %d”, a,b);
Result:
a. 1 0
b. 1 1
c. 11
d. Three answers above are wrong.
24. Given a short code:
#include<stdio.h>
int a,b;
main()
{
switch(a-b?5:b++)
{
default: a=b+=2;
case 5: b+=5;
case 1: a--;
}
}
Result:
a. a=2, b=8
b. a= -1, b=1
c. a= -1, b=6
d. Three answers above are wrong.
25. Given a short code:
#include<stdio.h>
int a=1,b=2;
main()
{
switch(a=3)
{
case 3: a+=2;
default: b++;
break;
case 0: a--;
}
}
Result:
a. a=1, b=3
b. a=5, b=3
c. a=4, b=3
d. Three answers above are wrong.
26. Given a short code:
#include<stdio.h>
int change(int *a);
main()
{
int x=3, y=0;
while(x>change(&y)) ;
printf(“%d”,y);
}
int change(int *a)
{
static int temp=1;
*a+=temp++;
return temp;
}
Result:
a. Print 0
b. Wrong syntax
c. Print 1
d. Print 3
Given a short code(is used for 27, 28, 29,30)
#include<stdio.h>
void func1(int *a, int b);
void func2(int *a, int *b);
main()
{
int a=15, b=8;
func1(&b,a);
printf(“%d %d”, a,b);
func2(&a,&a);
printf(“%d %d”,a,b);
}
void func1(int *a, int b)
{
*a+=b++;
func2(&b,a);
printf(“%d %d”, *a, b);
return;
}
void func2(int *a, int *b)
{
if(*a>*b)
*a+=*b;
else *a-=2;
printf(“%d %d”, *a, *b);
return;
}
27. The function func2 outputs:
a. 14 23
b. 13 13
c. Both a,b are correct.
d. Both a, b are wrong.
28. The function func1 outputs:
a. 23 14
b. 14 23
c. 23 23
d. Both a,b are correct.
29. The output of printf in main function BEFORE invoking func2:
a. 15 8
b. 15 23
c. 13 8
d. Three answers above are wrong.
30. The output of printf in main function AFTER invoking func2:
a. 15 8
b. 13 23
c. 13 8
d. Three answers above are wrong.
Answer: 1.C 2.C 3.B 4.A 5.B 6.C 7.A 8.A 9.D 10.B 11.A 12.D 13.D 14.C 15.B 16.C 17.C 18.D 19.A 20.C 21.A 22.C 23.A 24.A 25.B 26.D 27.C 28.D 29.B 30.B
Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts
Thursday, March 17, 2016
PHP Quiz
Time: 20 minutes
Question .No: 18
Allowed: pencil + a piece of paper
Question .No: 18
Allowed: pencil + a piece of paper
1. What will the following PHP script display?
<?php
function get_sum(){
global $var;
$var = 5;
}
$var = 10;
get_sum();
echo $var;
?>
A. 15
B. NULL
C. 5
D. 10
The same question if ignoring the line global $var;
2. Which of the following structures are not supported in PHP5? (more than one can be selected)
A. Multiple inheritance
B. Abstract classes
C. Interfaces
D. Public and private method
3. Is it true that functions in PHP cannot be overloaded or redefined?
A. Yes
B. No
4. How could the expression in "echo" below is fixed?
<?php
$arr['one'] = 14;
echo "Event happended $arr['one'] days ago";
?>
A. " .$arr['one']. "
B. $arr{one}
C. {$arr['one']}
5. What does the following PHP script do? (more than one can be selected)
<?php
$id = 3;
$str = "active$id";
$$str = 1;
?>
A. Sets the variable $str to 1
B. Declares $active3 as a new variable
C. Sets the variable $str to "active3"
D. Nothing. The script is invalid
6. How many parameters can the following function accept?
<?php
function get_sum()
{
//...
}
?>
A. 0
B. 1
C. Any number
7. What is "herodoc" used for?
A. Creating multi-line strings with quotation marks
B. Creating single-line strings with quotation marks
C. Creating multi-line strings without quotation marks
D. Creating single-line strings without quotation marks
8. Can "echo" accept more than 1 parameter?
A. No
B. Yes
9. What is "<<<" operator used for?
A. To declare a regular expression
B. It is similar to "echo"
C. To declare a string variable
10. What will the following PHP script display?
<?php
abstract class Foo
{
abstract function bar(array $params=NULL);
}
class Moo extends Foo
{
public function bar(array $params)
{
echo count($params);
}
}
$c = new Moo();
$c->bar(array(5));
?>
A. 1
B. 5
C. 0
D. Fatal error
11. How do you start a PHP session?
A. Using session_start()
B. Using session_set()
C. Using session_register()
D. Using the variable $_SESSION
12. Which of the following statements about abstract classes are true? (more than one can be selected)
A. It is necessary to instantiate at least one object of an abstract class
B. Methods declared as abstract define only their signature and cannot contain any functionality
C. Methods declared as abstract contain functionality which cannot be overridden by the classes which inherit them
D. It is not possible to instantiate an object of an abstract class
13. What will the following PHP script display?
<?php
$str = 123;
echo "Value of variable - \$str";
?>
A. Value of variable - $str
B. Value of variable - 123
C. Value of variable - \$str
The same question with:
echo "Value of variable - $str";
echo 'Value of variable - \$str';
echo 'Value of variable - $str';
14. Which function returns a list of reponse headers?
A. header_getAll()
B. headers()
C. headers_list()
D. headers_send()
15. What is the following PHP script display?
<?php
$number = array(0.57,"21.5", 40.52);
if (in_array(21.5, $number,true)) echo "The value 21.5 is found";
else echo "21.5 is not found";
?>
A. "21.5 is not found"
B. "The value 21.5 is found"
C. Nothing. The script is invalid
16. What is the difference between accessing class methods via "->" and accessing via "::"?
A. "->" is for static methods, "::" is for non-static methods.
B. "->" is for static methods, "::" is for all methods.
C. "->" is for all methods, "::" is for static methods.
D. "->" is for non-static methods, "::" is for static methods.
E. There is no difference.
17. Which change will make the following PHP script display the string "Hello, World!"?
<?php
function myfunction()
{
???
print $string;
}
myfunction("Hello, World!");
?>
A. Replacing ??? with $string = $argv[1];
B. Replacing ??? with $string = get_function_args();
C. Replacing ??? with list($string) = func_get_args();
D. Nothing can be replaced.
18. Which function is best suited for removing markup tags from a string?
A. reg_replace()
B. strip_markup()
C. strip_tags()
D. str_replace()
Answer: 1.C 2.A 3.A 4.A 5.B,C 6.C 7.C 8.B 9.A 10.D 11.A 12.B,D 13.A 14.C 15.A 16.D 17.C 18.C
Ref:
http://www.zendexam.com/
http://php.net/
Answer: 1.C 2.A 3.A 4.A 5.B,C 6.C 7.C 8.B 9.A 10.D 11.A 12.B,D 13.A 14.C 15.A 16.D 17.C 18.C
Ref:
http://www.zendexam.com/
http://php.net/
Subscribe to:
Posts (Atom)