Time Left - 15:00 mins
GATE 2019 - P&DS Quiz-7 (Programming in C ) (App update required to attempt this test)
Attempt now to get your rank among 1140 students!
Question 1
#include <stdio.h>
int compare(int x,int y)
{
if(x<y)
return 1;
else
return 0;
}
void main(){
int k,s=0;
int arr[]={5,9,2,6,0,1,8};
for(int i=0;i<3;i++)
for(int j=i+1;j<7;j++)
{
if(compare(arr[i],arr[j]))
s=s+arr[j];
}
printf("%d",s);
}
What will be output of above code ?
int compare(int x,int y)
{
if(x<y)
return 1;
else
return 0;
}
void main(){
int k,s=0;
int arr[]={5,9,2,6,0,1,8};
for(int i=0;i<3;i++)
for(int j=i+1;j<7;j++)
{
if(compare(arr[i],arr[j]))
s=s+arr[j];
}
printf("%d",s);
}
What will be output of above code ?
Question 2
Consider the function func shown below:
int func(int num) {
int count = 0;
while (num) {
count++;
num>>= 1;
}
return (count);
}
The value returned by func(435)is______.
int func(int num) {
int count = 0;
while (num) {
count++;
num>>= 1;
}
return (count);
}
The value returned by func(435)is______.
Question 3
x = 2;
y= ((++x)*(++x)*(++x));
What is the value of y after the execution of the above C code?
y= ((++x)*(++x)*(++x));
What is the value of y after the execution of the above C code?
Question 4
Consider the following C program.
#include <stdio.h> #include <string.h> void printlength (char *s, char *t) { unsigned int c = 0; int len = ((strlen (s) - strlen (t)) > c) ? strlen (s) : strlen (t); printf("%d\n", len); } void main() { char *x = "abc"; char *y = "defgh"; printlength(x, y); }
Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int .The output of the program is
Question 5
Consider the following function implemented in C:
void printxy(int x, int y)
{
int *ptr;
x = 0;
ptr = &x;
y = * ptr;
* ptr = 1;
printf (“%d, %d,” x, y);
}
The output of invoking printxy (1, 1) is
Question 6
What does the following fragment of c program print?
#include<stdio.h>
int main()
{
static int GATE[]={100,200,300,400,500};
static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}
}
The output of the program is______
#include<stdio.h>
int main()
{
static int GATE[]={100,200,300,400,500};
static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}
int
**p = ptr;
ptr++;
printf
(
"%d%d"
, ptr - p, **ptr};
}
The output of the program is______
- 1140 attempts
- 1 upvote
- 10 comments
Apr 2GATE & PSU CS