Size of a character array should one greater than total number of characters in any string which it stores. In c every string has one terminating null character. This represents end of the string.So in the string “Network” , there are 8 characters and they are ‘N’,’e’,’t’,’w’,’o’,’r’,’k’ and ‘\0’. Size of array arr is seven. So array arr will store only first sevent characters and it will note store null character.

As we know %s in prinf statement prints stream of characters until it doesn’t get first null character. Since array arr has not stored any null character so it will print garbage value.

2.What will be output when you will execute following c code?

#include<stdio.h>

void main(){

char arr[11]="The African Queen";

printf("%s",arr);

}

Explanation:

Size of any character array cannot be less than the number of characters in any string which it has assigned. Size of an array can be equal (excluding null character) or greater than but never less than.

! Operator always return zero if a is non-zero number other wisie 1. In general we can say ! operator always returns an int type number. So

!a +b

=! (Any double type number) + Any character type number

= Any integer type number + any character type number

= Any integer type number

Note: In any expression lower type data is always automatically type casted into the higher data type. In this case char data type is automatically type casted into the int type data.

So sizeof (!a +b) = sizeof(Any int type number) = 2

So size of array arr is 2 and its data type is int. So

sizeof(arr) = size of array * sizeof its data type = 2* 2= 4

20.What will be output when you will execute following c code?

#include<stdio.h>

void main(){

char array[]="Ashfaq \0 Kayani";

char *str="Ashfaq \0 Kayani";

printf("%s %c\n",array,array[2]);

printf("%s %c\n",str,str[2]);

printf("%d %d\n",sizeof(array),sizeof(str));

}

Explanation:

A character array keeps the each element of an assigned array but a character pointer always keeps the memory address of first element.

As we know %s in prints the characters of stream until it doesn’t any null character (‘\0’). So first and second printf function will print same thing in the above program. But size of array is total numbers of its elements i.e. 16 byte (including ending null character). While size of any type of pointer is 2 byte (near pointer).