এখানে আমরা কিছু C এবং C++ কোড দেখব। এবং ফলাফল অনুমান করার চেষ্টা করুন. কোডগুলি কিছু রানটাইম ত্রুটি তৈরি করবে৷
৷1. শূন্য ত্রুটি দ্বারা বিভাজন অনির্ধারিত৷
৷উদাহরণ কোড
#include <iostream>
using namespace std;
int main() {
int x = 10, y = 0;
int z = x / y;
cout << "Done" << endl;
} আউটপুট
Runtime error for divide by zero operation
2. শুরু না করা ভেরিয়েবল ব্যবহার করার চেষ্টা করা হচ্ছে।
উদাহরণ কোড
#include <iostream>
using namespace std;
int main() {
bool x;
if(x == true)
cout << "true value";
else
cout << "false value";
} আউটপুট
false value (This may differ in different compilers)
3. নাল পয়েন্টার মান অ্যাক্সেস করার চেষ্টা করছে।
উদাহরণ কোড
#include <iostream>
using namespace std;
int main() {
int *ptr = NULL;
cout << "The pointer value is: " << *ptr;
} আউটপুট
Runtime error for accessing null pointer values
4. নাল পয়েন্টার মান অ্যাক্সেস করার চেষ্টা করছে।
উদাহরণ কোড
#include <iostream>
using namespace std;
int main() {
int array[10];
for(int i = 0; i<=10; i++) {
cout << array[i] << endl;
}
} আউটপুট
Runtime error for accessing item out of bound. Some compiler may return some arbitrary value, not return any error
5. স্বাক্ষরিত ইন্টের সীমা অতিক্রম করা।
উদাহরণ কোড
#include <iostream>
using namespace std;
int main() {
int x = INT_MAX;
cout << "x + 1: " << x + 1;
} আউটপুট
x + 1: -2147483648 circulate to the minimum number of signed int
6. স্ট্রিং লিটারেলে কিছু অক্ষর পরিবর্তন করার চেষ্টা করা হচ্ছে।
উদাহরণ কোড
#include <iostream>
using namespace std;
int main() {
char *str = "Hello World";
str[2] = 'x';
cout << str;
} আউটপুট
Runtime error because we are trying to change the value of some constant variables.