C Language Important Question Answer for BCA 2nd Semester

Contents

C Language Important Question for BCA 2nd Semester

C Language Important Question Answer for BCA 2nd Semester :- In this post we upload the most important questions of BCA 2nd semester c language with answer. the given question very very important. so I unloaded this all important question with answer. student easily read and learn this all question and get highest marks of their c language paper.

C Language Important Question Answer for BCA 2nd Semester

(Long Questions)

1) what is an array? Explain 2D array with memory representation.

Ans. Array:  array is a collection of similar data types which stored in contiguous memory location. Array helps to declare many variable at a one time. Array always started with zero. And the last length of the array is n-1. The given n means the total of the array. And the address of the array always contiguous memory. The address of the array depends upon data types of array.

Two Dimensional Array [2D array]

The 2 Dimensional Array are used form of the matrix (row and Coolum).

Syntax of 2D array: – This is the syntax of 2 dimensional array.

<DataTypes>ArrayName[Row_size][Coloum_size];

Declaration & Initialization of 2D Array:-

Declaration means how to be declare the 2d array. And initialization means how to assign the value of its. The total length of the Size = Row_size X Coloum_size.

Ex –

int arr[2][5] = { { 2,6,7,8,9,},{3,10,25,23,8}};

memory representation of 2d array

Memory Representation of 2D Array

2) Define pointer? Explain all function of DMA (Dynamic Memory Allocation).

Ans. Pointer: – Pointer means that store another variable address. The pointers is same to same variable but the difference between variable and pointer. The variable stored any value items. And pointer stored another variable address.

Declaration of Pointer

The Declare of the pointer with using Asteric (*) Sign. This asteric sign also known as Indirection Operator.

Syntax

int *ptr;

Note – The given ptr is pointer name.

Initialization of Pointer

Initialization pointer means assign the address of another variable.

Ex –

int * ptr;

ptr = &age;

Stored the address in any variable into pointer with using address operator (&).

Function of DMA (Dynamic Memory Allocation)

Dynamic Memory Allocation: – “The Dynamic Memory Allocation (DMA) are used to define the array size at a run time.” The compiler not know the size of an array. The DMA all operation performs the given function. The given function is library function.

Dynamic Memory Allocation Function

There are some function of the dynamic memory allocation. It given below

1, malloc()

2, calloc()

3, free()

4, realloc()

1, malloc() :- malloc stand for memory allocation. It takes number of bytes to be as an input and return a pointe of type void.

Syntax –

The given 30 entered by the user.

ptr = (int*)malloc(30*sizeof(int));

The Expression return null pointer if the memory is not be allocated.

2, calloc() :-  calloc() stands for continuous allocation. It initializes each memory block with a default value of 0.

Syntax –

The given 30 entered by the user.

ptr = (float*)calloc(30,sizeof(float));

if the space is not sufficient, memory allocation fails a null pointer is returned.

3, free() :- we can use this function to be deallocated the memory. The memory allocate using malloc/calloc is not deallocated automatically.

Syntax –

free(ptr);

Memory of ptr is released.

4, realloc() :- Sometimes the dynamically allocated memory is insufficient or more than required.

realloc is used to allocate memory of new size using the previous pointer and new size.

Syntax –

ptr = realloc(ptr, newsize);

ptr = realloc(ptr,3*sizeof int);

3) What is string? Explain all library function of string.

Ans. String: – String is the group of sequential character array. String is the one dimensional character array. String always terminate in the Null character ‘\0’. The string data types is char and string with space taking 1 bytes/ taking the string without using any loops.

Library Function of String

The standard library function is special function which is included as <string.h> library. It contain some function this are given below.

1) strlen(): – strlen() is a function of library <string.h>. it used to find the lenth of any string.

Ex –

Char str[20] = “string”;

int len;

len = strlen(str)

2) strcmp(): – strcmp is a inbuilt library function,. it library function is <string.h>. strcmp use to compare two string. The string will be same this function return also 0. Otherwise it return anuthing like -1,1,2 but not 0;

3) strcat(): – strcat function is the library inbuilt function. The library of this function is <string.h>. it used to perform string operations. It use to concatenate/ joint two string in one.

4) strcpy(): – the strcpy is the inbuilt library function. The library his function is <string.h>. and it used to copy string one to another.

Syntax –

strcpy(str1,str2)

str2 copy to str1.

4) What is structure and union? How to deferent union by structure. What is deference between them?

Ans.

Structure: – Structure is a user defined data types in which included different types of data in a group. The structure cannot be share the memory. The structure memory size is the total of the all data types.

Union: – the union same to same structure but the deference between it. The structure cannot share the memory and the union can share the memory. The union memory size depend upon the large size of data types.

How to deferent union by structure

The union deferent by structure the union can share the memory. And the structure cannot be share the memory. Otherwise the union and structure also same.

Deference between Union and Structure

Union Structure
The union is default data types. It is user defined data types. It make by user. The structure is default data types. And it is user-defined data types. It make by user.
Combination of many data types. Combination of many data types
Size = the large number of data types Size = total number of data types
The union can share memory. The structure cannot be share memory.
Contain lager memory because every data types having own memory. Contain only sufficient memory because it share memory.

5) Define macro. How to substitute the macro directives in our program?

Ans. Maco: – In c, the macro is used to define any constant value or any variable with its value in the entire program that will be replaced by the macro name. Where macro is contains the set of code that will be called when the macro name used in the program.

Substitute the macro directive in our program

The given example substitute the macro in our program.

Ex –

#include<stdio.h>

#define A (2+3) // it macro

#define B (4+5) // it macro

Void main()

Int C;

C = A*B;

printf(“C= %d”,C);

}

Output = 45

6) Explain Conditional Compilation directives. How to use it.

Ans. Conditional Compilation: – Conditional Compilation directives help to compile a specific portion of the program or skip compilation of some specific part of the program based on some conditions.

Conditional Compilation Directives are –

Directive Name Directive Description
1) #ifdef Return true if macro is defined.
2) #ifndef Return true if macro is not defined.
3) #if Test if a compile time condition is true.
4) #else The alternative for #if
5) #elif #else and #if one statement
6) #endif ends preprocessor conditional
7) #undef Remove definition of the specific macro

7) What is the file? Explain the modes of files.

Ans. File:- A file is an object which stored data or information. In computer, the data used in future we will require a file. Because the ram is volatile the data is lost but the file stored. In a rom memory and its store our data in a long time.

Modes of Files

We can use one of the following modes in the fopen() function.

Mode Description
“r” Open for reading. If the file does not exist, fopen() return null.
“rb” Open for writing. If the file does not exist, fopen() return null.
“w” Open for writing. If the file exists, the content will be over write.
“wb” Open for writing in binary. If the file exists, the content will be over write.
“a” Open for appended. If the file does not exist, it will be return created.

(Short Questions)

1) Difference between string and character array.

Ans.

String Character Array
 1). String is a collection of elements. 2). The character array is a collection of variable which stored in contiguous memory.
2). The String always ended with Null Character ‘\0’. 2). The Character array ended with the last variable of the array.
3). Slow access compare to character array. 3). Fast access compare to string.
4). The string used to static memory. 4). The character array used to static memory.

2) What is making bit field.

Ans.  The masking bit field is the method of saving the wastages memory. it saves the memory with using set the bit.

Ex –

#include <stdlib.h>

#include <stdio.h>

#include <stdint.h>

struct {

uint32_t year:23;

uint32_t day:5;

uint32_t month:4;

} typedef Bitfield;

int main() {

Bitfield date = {2020, 13,12 };

printf(“sizeof Bitfield: %lu bytes\n”, sizeof(date));

printf(“date: %d/%d/%d \n”, date.day, date.month, date.year);

return EXIT_SUCCESS;

}

Output

sizeof Bitfield: 4 bytes

date: 13/12/2020

3) What is the pointer? Explain.

  • Null Pointer
  • Void Pointer
  • Wild Pointer
  • Dangling Pointer

Ans. Pointer: – Pointer is the special variable which stored another variable address. There are some types of pointer.

Null Pointer: – Null pointer by assigning the null value at the time of pointer declaration. This method is useful when you do not assign any address to the pointer. A null pointer always contains value 0.

Void Pointer: – The void pointer is a generic pointer that isn’t associated with any data type. A void pointer can be type casted to any type, so it is instrumental in assigning the different types of variables to the void pointer.

Wild Pointer: – If a pointer isn’t initialized to anything, it’s called a wild pointer. Dereferencing a wild pointer has undefined behavior that may crash the program or give a garbage value.

Dangling Pointer: – A dangling pointer is a pointer that refers to a memory location that has been released or deleted.

4) Write the program to concatenate two string without using string library function?

#include<stdio.h>

#include<conio.h>

void main()

{

char str1[10];

char str2[10];

char str[20];

int i,j,k,l;

printf(“Enter first string: \n”);

scanf(“%s”, str1);

printf(“Enter second string: \n”);

scanf(“%s”, str2);

for(i=0;i<10;i++){

if(str1[i]==’\0′)

break;

}

for(j=0;j<10;j++){

if(str1[j]==’\0′)

break;

}

for(k =0; k<i-1; k++)

{

str[k] = str1[k];

}

int n = 0;

for(l=k;l < i+j-2;l++)

{

str[l] = str2[n++];

}

printf(“The string is: %s”, str);

getch();

}

 5) Deference between call by value and call by reference

Call by value Call by Reference
Call by value passed the value. Call by reference passed to address.
Value copied actual parameter to formal parameter. Have the both parameter in a same memory address.
Change the formal parameter value the value cannot be reflect into actual parameter. Because it copied value. Change the value the can reflect actual parameter because both value having in a same memory address.

(Very Short)

1) What is bitwise operator? Explain left shift and right shift.

Ans. Bitwise Operator: – bitwise operator are used for manipulating the data at bit level, also called as (bit level programming) bitwise operator. Bit level programing consist at 0 and 1.

Operator Description
& Bitwise And
| Bitwise OR
^ Bitwise Exclusive OR [XOR]
<< Bitwise Left Shift
>> Bitwise Right Shift

 

Left shit and Right Shift

Left shift: – the left shift operator is multiply by 2.

Ex-

0 0 0 0 1 1 1 0

14

14 << 1

0 0 0 1 1 1 0 0

 

Output = 28

Right shift: – the left shift operator is divided by 2.

Ex-

0 0 0 0 1 1 1 0

14

14 >> 1

0 0 0 0 0 1 1 1

Output = 28

2) Why need of masking bit field.

Ans. Bit masking: Bit masks are used to access specific bits in a byte of data. This is often useful as a method of iteration, for example when sending a byte of data serially out a single pin. In this example the pin needs to change it’s state from high to low for each bit in the byte to be transmitted

3) What is array? Explain 1D array.

Ans. Array: – An array is a collection of similar data types which stored in contiguous memory allocation. The array always started with 0 and the array last element is n-1. The array started address called lower bounded. And last element called upper bound.

1 Dimensional Array: –

Declaration & Initialization of 1D array

Syntax – <Datatypes>arrayname[lenth];

int age[8] = {10,20,30,40,50,60,70,80}; 

1d array memory represent

4) Explain difference between Binary File and text files.

Ans. There are some difference between Binary File and text files.

Text file Binary File
1 Its bit represent character. Its bits represent a custom data.
2 Less prone to get corrupt as change reflect as soon as made and can be undone. Can easily get corrupted, corrupted on even single bit change.
3 Store only plaint text in a file. Can store different types of data (audio, text, image) in a single file.
4 Widely used file format and can be opened in any text editor. Developed for an application and can be opened in that application only.
5 Mostly .text, .rtf, are used as extension to text files. Can have any application defined extension.

5) What is Nested Structure?

Ans. Nested Structure: – A structure inside another structure is called nested structure.

Ex –

// C program to implement

// the above approach

#include <stdio.h>

// Declaration of the outer

// structure

struct Organisation

{

char organisation_name[20];

char org_number[20];

// Declaration of the employee

// structure

struct Employee

{

int employee_id;

char name[20];

int salary;

// This line will cause error because

// datatype struct Employee is present ,

// but Structure variable is missing.

};

};

// Driver code

int main()

{

// Structure variable of organisation

struct Organisation org;

printf(“%ld”, sizeof(org));

}


App – Dream Topper (Play Store)

Www.DreamTopper.in

Www.YouTube.com/Dreamtopper

 

  • Thanks

 


(Long Questions)

  • What is an array? Explain 2D array with memory representation.
  • Define pointer? Explain all function of DMA (Dynamic Memory Allocation).
  • What is string? Explain all library function of string.
  • What is structure and union? How to deferent union by structure. What is deference between them?
  • Define macro. How to substitute the macro directives in our program?
  • Explain Conditional Compilation directives. How to use it.
  • What is the file? Explain the modes of files.

(Short Questions)

  1. Difference between string and character array.
  2. What is making bit field.
  3. What is the pointer? Explain.
  4. Null Pointer
  5. Void Pointer
  6. Wild Pointer
  7. Dangling Pointer
  8. Write the program to concatenate two string without using string library function?
  9. Deference between call by value and call by reference

(Very Short)

  1. What is bitwise operator? Explain left shift and right shift.
  2. Why need of masking bit field.
  3. What is array? Explain 1D array.
  4. Explain difference between Binary File and text files.
  5. What is Nested Structure?

 

 

1 thought on “C Language Important Question Answer for BCA 2nd Semester”

Leave a Comment

Your email address will not be published. Required fields are marked *