C programming Concept
1. Write a java code which returns a value.
public class Calculator {
    public static int add(int a, int b) {
        return a + b;
    }
    public static void main(String[] args) {
        int result = add(10, 20);
        System.out.println("The sum is: " + result);
    }
}
ব্যাখ্যা দেখুন
  • add() নামের একটা মেথড তৈরি করা হয়েছে যেটা দুইটা সংখ্যা (a এবং b) ইনপুট হিসেবে নিয়ে তাদের যোগফল রিটার্ন করে

  • main() মেথডে add(10, 20) কল করা হয়েছে — মানে ১০ আর ২০ পাঠানো হয়েছে মেথডে।

  • মেথড যোগফল হিসাব করে ৩০ রিটার্ন করেছে, যেটা result ভ্যারিয়েবলে সংরক্ষণ করা হয়েছে।

  • শেষে System.out.println() দিয়ে “The sum is: 30” প্রিন্ট করা হয়েছে।

8. Write JAVA Code

Question not Fully Collected

1-D array কীভাবে initialize করা যায়? একটা ফাংশন-এ কীভাবে array আমরা pass করতে পারি? 45th BCS, Computer Science(971)
1-D Array Initialization (Example) A 1-D array can be initialized at the time of declaration as follows:
int a[5] = {10, 20, 30, 40, 50};
Passing an Array to a Function (Example) An array can be passed to a function by using the array name:
#include <stdio.h>
void display(int arr[], int n) {
    int i;
    for(i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
}
int main() {
    int a[5] = {10, 20, 30, 40, 50};
    display(a, 5);
    return 0;
}
1-D Array Initialization (Example) 1-D array declaration-এর সময় নিচের মতো করে value দিয়ে initialize করা যায়:
int a[5] = {10, 20, 30, 40, 50};
Function-এ Array Pass করা (Example) Function parameter হিসেবে array-এর নাম ব্যবহার করে array pass করা হয়:
#include <stdio.h>
void display(int arr[], int n) {
    int i;
    for(i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
}
int main() {
    int a[5] = {10, 20, 30, 40, 50};
    display(a, 5);
    return 0;
}
এখানে function-এ array pass করলে আসলে array-এর base address pass হয়।
  1. What is the difference of the following: getc(), getchar(), getch() and getche()? [45th BCS, ICT 2024]
  2. What is the difference between Null and Void? [BCC AP 2023]
  3. What is the difference between sizeof c+1 and sizeof(c+1)? [BPSC AP 2023]
  4. Local variable এবং Global variable এর মধ্যে পার্থক্য লিখুন। [17th NTRCA(CSE) 2023]
  5. Write about the syntax of function. [BARC Programmer 2023]
  6. Distinguish between Compiler and Interpreter with example. [BPSC ADA, AP 2022; 40th BCS, PGCB SAE (CSE) 2021; 40th BCS 2020; BCC Programmer 2019]
  7. Formatted Input/output Statement কাকে বলে? Key-Board থেকে কিভাবে input নেওয়া যায়? %d এর অর্থ কী? [BPSC ANE 2020]
  8. What are the main objectives of structured programming? Write two advantages of structured programming. [SPARRSO 2020]
  9. Difference between getch() and getche(). [BBL AM (ICT) 2019]
  10. Write down the role of a linker. [BUET M.Sc. May-2016]
upcoming
WhatsApp Telegram Messenger