Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

C Programming :: Arrays

Home > C Programming > Arrays > General Questions

1. What is the output of the following problem ?

#include
int main()
{
func(1);
return 0;
}
func(int i){
static char *str[] = {"One","Two", "Three", "Four"};
printf("%s\n",str[i++]);
return;
}

Answer: Two

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

2. int main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
return 0;
}

Answer: mmmm aaaa nnnn

Explanation:

s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, in directing it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].

Workspace

Tags:

No Tags on this question yet!

3. What is the output of the following C Program?

#include
int main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
return 0;
}

Answer: 2 5 5

Explanation:

In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable.
In second sizeof the name str2 indicates the name of the array whose size is 5 (including the '\0' termination character).
The third sizeof is similar to the second one.

Workspace

Tags:

No Tags on this question yet!

4. What is the output of the following C Program?

#include
int main() {
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
return 0;
}

Answer: 77

Explanation:

p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11.
The value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes
'b'. ASCII value of 'b' is 98.
Now performing (11 + 98 - 32), we get 77("M"); So we get the output 77 :: "M" (Ascii is 77).

Workspace

Tags:

No Tags on this question yet!

5. What is the output of the following C Program?

#include
#define max 5
#define int arr1[max]
int main()
{
typedef char arr2[max];
arr1 list={0,1,2,3,4};
arr2 name="name";
printf("%d %s",list[0],name);
return 0;
}

Answer:

Explanation:

#defines are used for textual replacement whereas typedefs are used for declaring new types.

Workspace

Tags:

No Tags on this question yet!

6. What is the output of the following C Program?

#include
int main()
{
static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i; char *t; t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
return 0;
}

Answer: Compiler error: incompatible types in assignment

Explanation:

Array names are pointer constants. So it cannot be modified.

Workspace

Tags:

No Tags on this question yet!

7. What is the output of the following C Program?

#include
void main()
{
int a[10];
printf("%d",*a+1-*a+3);
}

Answer: 4

Explanation:

*a and -*a cancels out. The result is as simple as 1 + 3 = 4 !

Workspace

Tags:

No Tags on this question yet!

8. What will be output of the following "c" code?

#include
int main(){
int arr[]={6,12,18,24};
int x=0;
x=arr[1]+(arr[1]=2);
printf("%d",x); return 0;
}

Answer: 4

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

9. What will be output of the following "c" code?

#include
int main(){
int arr[3]={10,20,30};
int x=0;
x=++arr[++x]+ ++x+arr[--x];
printf("%d ",x);
return 0;
}

Answer: 43

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

10. What will be output of the following "c" code?

#include
int main(){
int a[]={10,20,30,40};
int i=3,x;
x=1*a[--i]+2*a[--i]+3*a[--i];
printf("%d",x);
return 0;
}

Answer: 60

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!