Differentiate between character array and integer array with respect to size and initialisation.

1 Answer

Answer :

Parameter
Character Array
Integer Array  
Size
Last location in character array is filled with '\0' so the array size should be so declared that it should have one last location for '\0' character.  
No extra location than the number of elements is required.
Initialization
Initialization can be done like : char str[4]={'a','b','c','\0'}; char str[4]="abc";
Initialization can be done like : int arr[4]={1,2,3,4}; 

Related questions

Description : Develop a program to accept an integer number and print whether it is palindrome or not.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int n,num,rev=0,digit,i; clrscr(); printf("Enter the number: "); scanf("%d",&num); n=num ... ;Number is palindrome"); else printf("Number is not palindrome"); getch(); }

Description : Develop a simple ‘C’ program for addition and multiplication of two integer numbers.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int a,b,add,mul; clrscr(); printf("Enter value for a and b:"); scanf("%d%d",&a,&b); add=a+b; ... b=%d\n",add); printf("\Multiplication of a and b=%d",mul); getch(); }

Description : Write a program to sort elements of an array in ascending order.

Last Answer : #include #include void main() { int a[5],i,j,temp; clrscr(); printf("\n Enter array elements:"); for(i=0;i

Description : Write a program to compute the sum of all elements stored in an array using pointers.

Last Answer : #include #include void main() { int a[5],sum=0,i,*ptr; clrscr(); printf("\n Enter array elements:"); for(i=0;i

Description : Illustrate initialization of two dimensional array with example.

Last Answer : Two dimensional array: The array which is used to represent and store data in a tabular form is called as two dimensional array. Such type of array is specially used to represent data in a matrix form. ... where outer loop will increment row and inner loop will increment column. Eg : for(i=0;i

Description : Define array. List its type.

Last Answer : Array is a fixed-size sequential collection of elements of the same type. Types: 1. One dimensional 2. Multi dimensional

Description : State difference between array and string. 

Last Answer : Array String Array can be of any type like int, float, char.   String can contain only characters. Element Elements in an array can be accessed using its position like a[2]. ... . Array size once declared cannot be changed   String size can be modified using pointer.  

Description : Define Array.

Last Answer : An array is a collection of data items, all of the same type, accessed using a common name. A one-dimensional array consists of similar type of multiple values in it. A two dimensional array consists of row and column.

Description : Design a programme in C to read the n numbers of values in an array and display it in reverse order.

Last Answer : #include #include #define max 50 void main() { int a[max],i,n; clrscr(); printf("\n Enter number of elements:"); scanf("%d",&n); printf("\n Enter array element:"); for(i=0;i=0;i--) printf("\t%d",a[i]); getch(); }

Description : Define: (i) Two dimensional array (ii) Multi-dimensional array

Last Answer : (i) Two dimensional array Two dimensional array is a collection of similar type of data elements arranged in the form of rows & columns. E.g. Array can be declared as int arr[3][3]; In this there can be 9 ... (3d) array. For example, float y[2][4][3]; Here, The array y can hold 24 elements.

Description : Write a program using switch statement to check whether entered character is VOWEL or CONSONANT

Last Answer : #include<stdio.h> #include<conio.h> void main() { char ch; clrscr(); printf("Enter character:"); scanf("%c",&ch); switch(ch) { case 'a': ... break; default: printf("\n Entered character is CONSONANT"); } getch(); }

Description : Calculate factorial of a number using recursion.

Last Answer : #include #include int factorial(int no) { if(no==1) return(1); else return(no*factorial(no-1)); } void main() { intfact,no; clrscr(); printf("\n Enter number"); scanf("%d",&no); fact=factorial(no); printf("\n Factorial number=%d",fact); getch(); }

Description : Write a function to print Fibonacci series starting from 0, 1.

Last Answer : void Fibbo() { inta,b,c,limit,i; printf("\n Enter number:"); scanf("%d",&limit); a=0; b=1; printf("%d\t%d",a,b); for(i=0;i

Description : Write a program to calculate sum of all the odd numbers between 1 to 20.

Last Answer : Write a program to calculate sum of all odd element of 1D array

Description : Write a program to read two strings and find whether they are equal or not.

Last Answer : #include<stdio.h> #include<conio.h> #include<string.h> void main() { char st1[20],st2[20]; printf( enter string 1 ); scanf( %s ,st1); printf( enter second string ); ... 0) printf( \nboth strings are equal ); else printf( \nstrings are not equal ); }

Description : Write a program to add, subtract, multiply and divide two numbers, accepted from user switch case.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int a,b,ch,add,sub,mul,div; clrscr(); printf("\n1 for addition \n2 for substraction"); printf("\n3 for multiplication \ ... break; default: printf("Invalid choice...."); } getch(); }

Description : Illustrate the use of break and continue statement with example.

Last Answer : Break: It breaks the execution of the loop which allows exiting from any loop or switch, such that break statement skips the remaining part of current iterations of the loop.  Syntax: ... then execution control will skip remaining statements of loop & will start next iteration of loop 

Description : Write an algorithm to determine the given number is odd or even.

Last Answer : Step 1- Start Step 2- Read / input the number. Step 3- if n%2==0 then number is even. Step 4- else number is odd. Step 5- display the output. Step 6- Stop

Description : List the categories of functions and explain any one with example.

Last Answer : Different categories of function: 1) Function with no arguments and no return value. 2) Function with arguments and no return value. 3) Function with no arguments and return value. 4) Function with ... have 4 and y will have 5 as their values and s will store value returned by the function.

Description : Describe the following terms: (i) Keyword (ii) Identifier (iii) Variable (iv) Constant

Last Answer : (i) Keyword: Keywords are special words in C programming which have their own predefined meaning. The functions and meanings of these words cannot be altered. Some keywords in C Programming are if, while, ... or a string literal. There are enumeration constants as well. Example: 121 234 3.14 

Description : Explain nested if-else with example.

Last Answer : When a series of decision is required, nested if-else is used. Nesting means using one if-else construct within another one. If the condition in the outer if, is true, then only the inner if-else will get executed. ... } else { printf("Number is less than 5"); } getch(); }

Description : Write a program to declare structure student having rollno, name & marks.

Last Answer : Accept and display data for three students. #include #include void main() { int i; struct student{ int rollno; char name[20]; int marks; } s[3]; clrscr(); for(i=0;i

Description : State the importance of flow chart. 

Last Answer : A flowchart is a type of diagram that represents an algorithm. It is a visual representation of a sequence of steps to complete the process. A flow chart describes a process using symbols rather ... to communicate a module's ultimate design, depending on the level of detail of the flowchart.

Description : Draw flow chart for addition of two numbers.

Last Answer : a + b sum 2 + 5

Description : State the syntax to declare pointer variable with example.

Last Answer : General syntax to declare pointer. datatype *var_name; Eg: int var = 20;

Description : State the Relational operators with example.

Last Answer : == - returns true if the values of two operands are equal else returns false. E.g: if (A= = B){ } != - returns true if values of two operands are not equal, else returns false E.g: if (A! = B ... the first operand is greater than or equal to the second, else returns false. E.g: if (A> = B){ }

Description : State the syntax & use of strlen ( ) & strcat ( ) function.

Last Answer : strlen( ): calculates the length of the string Syntax: strlen(s1); strcat():concatenates two strings Syntax: strcat(s1,s2)

Description : Write a program to sum all the odd numbers between 1 to 20. 

Last Answer : #include<stdio.h> #include<conio.h> void main() { int sum=0,i; clrscr(); for(i=1;i<=20;i++)  { if(i%2==1) sum=sum+i; }  printf(“sum of odd no“s between 1 to 20 is %d”,sum); getcht); }

Description : Write a program to reverse the number 1234 (i.e. 4321) using function. 

Last Answer : #include #include void findReverse(); void main() { findReverse(); } void findReverse() {  int num, res=0,ans=0; clrscr(); printf("Enter the number"); scanf("%d", &num); while(num!=0) { res=num%10; ans=ans*10+res; num=num/10; } printf("Reverse number is %d", ans); getch(); }

Description : Draw flowchart for checking weather given number is prime or not.

Last Answer : flowchart for checking weather given number is prime or not.   

Description : State four arithmetic operations perform on pointer with example.

Last Answer : The pointer arithmetic is done as per the data type of the pointer. The basic operations on pointers are Increment: It is used to increment the pointer. Each time a pointer is incremented, it points to the ... address 1004, Then ptr-2 shows 1004-(2*2) = 1000 as decremented location for an int. 

Description : Distinguish between call by value and call by reference.

Last Answer : Call by value Call by reference   A copy of actual arguments is passed to respective formal arguments.   The address of actual arguments is passed to formal arguments Actual ... is not reflected in other functions  Changes made in the function is reflected outside also.  

Description : Declare a structure student with element roll-no and name.  

Last Answer : struct student { int roll_no; char name[20]; };

Description : State any two differences between while and do-while statement.  

Last Answer : while Do-while In 'while' loop the controlling condition appears at the start of the loop.  In 'do-while' loop the controlling condition appears at the end of the loop. The iterations ... is an exit controlled loop while(condition) { body }   do { body }while(condition);

Description : Write the syntax of switch case statement. 

Last Answer : switch(variable) { case value1: statements break; case value2: statements; break; . . . default: statements; break; }

Description : Draw flowchart for checking whether given number is even or odd. 

Last Answer : flowchart for checking whether given number is even or odd.  

Description : Write a program to accept two numbers from user and perform addition, subtraction, multiplication and division operations using pointer.

Last Answer : #include #include void main() { int no1,no2,*ptr1,*ptr2,result; clrscr(); printf("Enter no1:"); scanf("%d",&no1); printf("\nEnter no2:"); scanf("%d",&no2); ptr1=&no1; ptr2=&no2; ... "\n Multiplication=%d",result); result=*ptr1/(*ptr2); printf("\n Division=%d",result); getch(); }

Description : If the value of a number (N) is entered through keyboard. Write a program using recursion to calculate and display factorial of number (N). 

Last Answer : #include<stdio.h> #include<conio.h> int factorial(int N); void main() { int N,fact; clrscr(); printf("Enter number:"); scanf("%d",&N); fact=factorial(N); printf( ... N) { if(N==1) return(1); else return(N*factorial(N-1)); }

Description : Write a program to declare structure employee having data member name, age, street and city. Accept data for two employees and display it.

Last Answer : #include<stdio.h> #include<conio.h> struct employee { char name[10],street[10],city[10]; int age; }; void main() { int i; struct employee e[2]; clrscr(); for(i=0;i<2 ... =%s",e[i].street); printf("\n City=%s",e[i].city); } getch(); }

Description : Write a program to Print values of variables and their addresses. Note : 1) Variables can be of any data type. 2)Use of & or pointer to display address shall be considered. 

Last Answer : #include #include void main() { int a,b; clrscr(); a=5; b=10; printf("\n Value of a=%d",a); printf("\n Address of a=%u",&a); printf("\n Value of b=%d",b); printf("\n Address of b=%u",&b); getch(); }

Description : Write a program for addition of two 3 x 3 matrices.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j; clrscr(); printf("Enter first matrix elements:\n"); for(i=0;i<3;i++) { for(j=0;j<3 ... (j=0;j<3;j++) { printf("%d\t",c[i][j]); } } getch(); }

Description : Write a program to swap two numbers using call be value.

Last Answer : #include<stdio.h> #include<conio.h> void swap(int a, int b) { int temp; temp=a; a=b; b=temp; printf("Numbers after swapping no1=%d and no2=%d",a,b); } void ... ;Numbers before swapping no1=%d and no2= %d",no1, no2); swap(no1,no2); getch(); }

Description : Write a program to accept a string as input from user and determine its length. [Don’t use built in library function strlen()]

Last Answer : #include #include void main(){ char str[50]; int i, len=0; clrscr(); printf("Enter a string"); scanf("%s",&str); for(i=0; str[i]!='\0'; i++){ len++; } printf("The length of string is %d",len); getch(); }

Description : Write a program to accept the value of year as input from the keyboard & print whether it is a leap year or not. 

Last Answer : #include #include void main() { int year; clrscr(); printf("Enter year"); scanf("%d",&year); if(year%4==0) { printf("Year %d is a leap year",year); } else { printf("Year %d is not a leap year",year); } getch(); }

Description : Write a program to accept marks of four subjects as input from user. Calculate and display total and percentage marks of student. 

Last Answer : #include<stdio.h> #include<conio.h> void main() { float marks[4]; float total=0.0, perc=0.0; int i; clrscr(); for(i=1;i<=4;i++) { printf("Enter marks of ... is :%f",total); perc=total/4; printf("Percentage is %f",perc); getch(); }

Description : Write algorithm and draw flow-chart to print even numbers from 1 to 100.

Last Answer : Here's one possible algorithm to print even numbers from 1 to 100: Start with a variable i equal to 1. Check if i is less than or equal to 100. If i is less than or equal to 100 ... and increments `i` by 1. The loop continues until `i` is greater than 100, and the program ends.

Description : Explain strlen() and strcpy() function with example.

Last Answer : strlen()- this function is used to find the length of a string. It counts the number of characters comprising the string. Syntax: strlen(char[] str)- finds the length of the string str. Example: ... ; strcpy(dest,source); printf("\n%s %s",source, dest); getch(); }

Description : Explain conditional operator with example.

Last Answer : Conditional operators return one value if condition is true and returns another value is condition is false. This operator is also called as ternary operator as it takes three arguments. Syntax : (Condition? true_value: false_value) ... 0?printf("%d is even",i):printf("%d is odd",i) ; getch(); }

Description : Explain User defined function with example.

Last Answer : Functions are basic building blocks in a program. It can be predefined/ library functions or user defined functions. Predefined functions are those which are already available in C library. User defined functions are those which are ... value is: %d",a); } void main() { myFunc(10); getch() }

Description : Explain increment and decrement operator.

Last Answer : Increment operator is used to increment or increase the value of a variable by one. It is equivalent to adding one to the value of the variable. The symbol used is ++. The decrement operator is used to decrement ... n--; printf("\nvalues after changing%d%d",m,n); getch(); }