Question: Question 1: Which of the function definitions for a function isletter will correctly determine whether a character is an alphabetic letter and returns 1 for
Question 1: Which of the function definitions for a function isletter will correctly determine whether a character is an alphabetic letter and returns 1 for true and 0 for false?
1.
int isletter(char ch)
{
if((ch >= a && ch <= z)||(ch >= A && ch <= Z))
return 1;
else
return 0;
}
2.
int isletter(char ch)
{
if((ch >= a || ch <= z)&&(ch >= A || ch <= Z))
return 1;
else
return 0;
}
Group of answer choices
No answer text provided.
2
No answer text provided.
1
Flag this Question
Question 2
The following program supposes to sum all entered int values that are greater than 5. It takes integer input and -1 indicates the end of input. It compiles without any error message, and it executes without error message, but nevertheless is wrong. What is wrong with the program?
#include
int main()
{
int x, sum = 0;
while (x != -1)
{
scanf("%d", &x);
if (x > 5);
sum = sum +x;
}
printf("The sum of values > 5 is %d ", sum);
}
Group of answer choices
The while header needs a semicolon at the end of its line.
The semicolon at the end of the if statement causes all entered values to be summed.
The semicolon at the end of the if statement is an error that the compiler should catch.
The while loop does not terminate when input is -1.
Flag this Question
Question 3
Which one of the following definition of the swap function would exchange the values of the variables i and j successfully?
swap(&i, &j); /* exchange values of i and j */
a)
void swap(int *x, int *y)
{ int tmp;
tmp = *x;
*x=*y;
*y=*x;
}
b)
void swap(int *x, int *y)
{ int tmp;
tmp = *x;
*x=*y;
*y=tmp;
}
c)
void swap(int *x, int *y)
{ int tmp;
tmp = *x;
*y=*x;
*x=tmp;
}
Group of answer choices
c
a
b
Flag this Question
Question 4
Consider the following recursive function.
int compute(int low, int high){
if (low == high) return 0;
else return 1 + compute(low+1, high);
}
What does a call compute(3, 5) return?
Group of answer choices
5
3
2
0
4
Flag this Question
Question 5
Which of the following defines a recursive function for calculating the factorial of a number?
a)
int fact(int n)
{
if (n==1) return 1;
else return fact(n*(n-1));
}
b)
int fact(int n)
{
if (n==1) return 1;
else return n*(n-1);
}
c)
int fact(int n)
{
if (n==1) return 1;
else return n*fact(n-1);
}
Group of answer choices
c
a
b
Flag this Question
Question 6
What is the output the following program?
#include
int b=0, c =2;
void f();
int main(void){
int b = 2;
c++;
f();
return 0;
}
void f(void){
int b = 5;
b++;
printf(%d %d , b, c);
}
Group of answer choices
2 2
6 3
6 2
2 3
Flag this Question
Question 7
Which of the following statements will update the value of num to 36 using the int pointer variable p? Assume that num and p have declared and initialized as follows:
int num = 25;
int *p;
p = #
Group of answer choices
*p = 36;
&p = 36;
p = 36;
&num = 36;
Flag this Question
Question 8
Assume i is int and p and q are pointers to int, which assignment is illegal?
Group of answer choices
p = &i;
p = q;
p = *&q;
p = i;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
