EGN3211.Chapter.7.Non Graded Questions
EGN3211.Chapter.7.Non Graded Questions
EGN3211.Chapter.7.Non Graded Questions
http://www.cquestions.com/2012/02/data-type-questions-in-c.html
http://www.indiabix.com/c-programming/pointers/
Directions
Step 1: Identify solution without any assistance (compiler, textbook, Google, etc).
Step 2: Research (textbook, Google), work (compiler), and implement the solution.
Resolve the difference by collaborating and corroborating with your classmates. If still not resolved, check with me.
Due to compilers using different standards and some not conforming to standards, it is possible for the output to be different or
incorrect. It is important that you identify the correct version and use that as reference for the exam preparation.
Some questions might refer to topics we have not covered yet for the current exam. Save it for the future exam.
If the code generates a compilation error, then identify the reason for the error and fix it.
Questions Lesson(s) Learned
1 What is the outcome/output of the following C program, if Asq table
any? Pointing to part of function
#include<stdio.h> https://www.cquestions.com/2010/04/c-questions-
void main(void){ answers.html
int a = 320;
char *ptr;
ptr =( char *)&a;
printf("%d ",*ptr);
}
2 What is the outcome/output of the following C program, if Ptr to ptr
any? K is ptr to ptr
#include<stdio.h> Prints content of k prints address of k
void main(void){ *k prints I
int i = 3; **k prints g reference twice go to j then go to i
int *j; &=address
int **k; Content of pointer is what to look for
j=&i;
k=&j;
printf("%u %u %d ",k,*k,**k);
}
3 What is the outcome/output of the following C program, if Type cast
any?
Cant use pointer
#include<stdio.h>
void main(void){
int a = 10;
void *ptr = &a;
int *p = ptr;
printf("%u",*p);
printf("%u",*ptr);
4 What is the outcome/output of the following C program, if Pointer arithmetic “position from a to b in
any? memory”
#include<stdio.h> p-q is difference between memory location
#include<string.h>
void main(void){ *p-*q is difference between physical digits
int a = 5,b = 10,c;
int *p = &a,*q = &b;
c = p - q;
printf("%d" , c);
c = *p - *q;
printf("%d" , c);
}
#include<stdio.h>
void main(void){
int i = 8 , j;
int *p , *q;
p = &i;
q = &j;
j = i;
printf("%d %d",*p,*q);
j= &i;
printf("%d %d",*p,*q);
}
6 What is the outcome/output of the following C program, if
any?
#include<stdio.h>
void main(void){
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
printf("%d %d",j,k);
printf("%p %p",j,k);
}
9 What will be the outcome/output of the program, if any? Purpose of pointer is to point to a variable
#include<stdio.h> C
void main(void)
{ It points to nothing
int *x;
*x=100;
printf( “ %d”,*x);
}
A. Address of x
B. 100 * the initial value in x.
C. Run time error
D. 100
10 What is the output of this C code?
555
void main(void)
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d %d %d\n", k, *p, **m);
}
• A. 5 5 5
• B. 5 5 3000
• C. 5 2000 3000
• D. Run time error
void main(void)
{
int x = 0;
int *ptr = &5;
printf("%p\n", ptr);
}
• A. 5
• B. Address of 5
• C. 2000
• D. Compile error
12 What is the output of this C code?
x:2000
ptr:3000
abc:4000
int main(void)
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d/n", *ptr, a);
}
• A. 10,10
• B. 10,11
• C. 11,10
• D. 11,11
18 What is the output of this C code?
int main(void)
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
a++;
printf("%d,%d", *ptr, a);
}
#include<stdio.h>
void main(void){
char arr1[5]="Lion";
char arr2[]=”King”;
printf("%s",arr1);
}
20 What is the outcome/output of the following C program, if
any?
#include<stdio.h>
void main(void){
char arr1[4]="Lion";
char arr2[]=”King”;
printf("%s",arr1);
}
21 What is the outcome/output of the following C program, if
any?
#include<stdio.h>
void main(void){
char arr1[5]="The Toy Story";
char arr2[]="Lion King";
printf("%s",arr1);
}
22 What is the outcome/output of the following C program, if
any?
#include<stdio.h>
void main(void)
{
char str1[] = "Hello";
char str2[] = "Olleh";
if(str1 == str2)
printf("Equal\n");
else
printf("Unequal\n");
}
A. Equal
B. Unequal
C. Error
D. None of above
23 What is the outcome/output of the following C program, if
any?
#include<stdio.h>
void main(void)
{
char str1[] = "Hello";
char str2[] = "Help";
if(*str1 == *str2)
printf("Equal\n");
else
printf("Unequal\n");
}
#include<stdio.h>
void main(void)
{
char str[20] = "Hello";
char *const p=str;
*p+1=’M’;
printf("%s\n", str);
}
A. Mello
B. HMello
C. HMllo
D. Compile Error : cannot change due to const pointer
E. Hello
25 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);
26 What is the outcome/output of the following C program, if
any?
#include<stdio.h>
void main(void)
{
char str1[] = "Florida Capital";
char str2[] = "Florida State";
char *s1 = str1, *s2=str2;
while(*s1 == *s2){
printf("%c", *s1);
s1++;
s2++;
}
printf("\n");
}
27 What will be the output of following program?
#include<stdio.h>
#include<string.h>
int main(void){
char *ptr1 = NULL;
char *ptr2 = 0;
strcpy(ptr1," c");
strcpy(ptr2,"questions");
printf("\n%s %s",ptr1,ptr2);
return 0;
}
(A) c questions
(B) c (null)
void main(void)
{
char str1[] = "Hello";
char str2[10];
char *t, *s;
s = str1;
t = str2;
while(*t=*s)
*t++ = *s++;
printf("%s\n", str2);
}
29 What is the outcome/output of the following C program, if
any?
#include<stdio.h>
void main(void)
{
char str1[] = "Hello";
char str2[10]=”Star Wars”;
char *t, *s;
s = str1;
t = str2;
while(*t=*s)
*t++ = *s++;
printf("%s\n", str2);
}
30 What will be the output of the following program?
#include<stdio.h>
int main(void)
{
char a[] = "EGN";
char *p = "3211";
a = "3211";
p = "EGN";
printf("%s %s\n", a, p);
return 0;
}
31
What will be the output of the following program, if
any?
#include<stdio.h>
void main(void){
int i;
ptr++;
for (i=0;i<3;i++)
{
(*ptr)++;
}
for (i=0;i<3;i++)
{
printf("%u ", arr[i]);
}
32 Given
#include<stdio.h>
void main(void)
{
int a[3][4];
fun(a);
}
Which of the following is the correct way to define the
function fun() for the above program?
A.
void fun(int p[][4])
{
}
B.
void fun(int *p[4])
{
}
C.
void fun(int *p[][4])
{
}
D.
void fun(int *p[3][4])
{
}
33 Intentionally left blank